I'm kind of at a loss of words for how to properly ask this. Basically instead of Xcode "smart groups", I want the groups to physically translate into directories on the filesystem. How is this done in Xcode 3.1.2?
In Xcode the file structure is a bit of a misnomer, the structure that you are seeing in your Xcode project is a reference mapping of your project not a relational mapping of the structure where your project exists. For example, if you create a group in in the project at the root of the project named 'foo' this creates a reference to a container 'foo' that is managed by the project settings, it does not create a folder named 'foo' in the root directory where your applications exists in the file system. This is a point of contention for many developers using Xcode.
Instead, I would suggest (as #smorgan eluded to) that you create your folder structure in the project folder in the file system (Finder), example, navigate to your project and create folder 'bar'. Then in your project control-click on the project and select ADD > Existing Files... and select the folder. This will import the 'bar' folder into your project - and in fact just creates a reference pointer named 'bar' for said location in your project.
If you are they type of person who likes to have a standard or defined structure for your projects, create a project folder and all of the folders and subfolders that you'd normally have - the project skeleton/tree. This may have Source and Resources at the root and then inside Resources you might have additional folders like Images, Audio, Views, Cells, etc... Your Source folder may have UI, Model, Util, etc... and UI may have Start, Settings, App, etc... Once you have your default project folder defined ZIP the root folder up and name it something like "XCode Project Outline" or something that has meaning to you.
When you have a new project you're about to start, copy the ZIP file to where you want your project to live and simple unZip the file and name the folder the name of the project. Then create the new project file in the folder and then follow the ADD Existing File.../Folders... (recursive = checked) and it will add your entire project folder hiarchy to the project. For a more advance bit of magic; include your common bits of application framework that are not application specific and have those files in your ZIP'd file. Then when you unZip and add the folder hierarchy you'll also be adding your basic files (.h, .m, etc...) as well in one quick and easy fell swoop.
One thing I should mention is that if you start from a project you already have and that project is under version control, you'd be best to "Export" the project from your repository. This will build out all of the files based on the current version in (head) and remove all of the hidden .svn references. You can then prune and modify that folder as you see fit to create your project folder template ZIP file. Good luck and happy coding!
If I'm correctly understanding what you are looking for, the answer is to right-click on the project in the Groups & Files column, select Add > Existing Files..., and then pick the root folder that you want mapped in. In the options sheet that will pop down, change the default "Recursively create groups for any added folders" to "Create Folder References for any added folders".
Related
I'm curious when using Xcode.
I always need to choose an option when copying the open source class files I need for my project.
The options are "Create groups" and "Create folder references".
I've read the difference between the two already.
But it is not understood at all.
When I chose one of the two options, I deleted the file from my project and the open source class file was deleted at the same time.
I do not want it.
I want to always exist as an independent file. What should I choose?
It took me a while to understand the difference between those two options so I thought I'd share:
I'm writing this when Xcode 12 is the current version
The biggest difference is how the imported folder / file will be accessible from the finder. Let's say you want to import a new folder to your Xcode project. When you choose Create groups Xcode will import your new folder and create a group (the yellow icon). When you go to your project's directory (using Finder) you should see a folder named like the one you've just imported, but any additional files you put to this folder trough Finder won't be visible in your Xcode project.
When you choose Create folder references the imported folder will have a classic blue folder icon in Xcode. This new folder will also be visible when you go to your projects directory, but now every new file you put there will also appear in your Xcode project.
If you want to know more just read this explanation http://www.thomashanning.com/xcode-groups-folder-references/
It's pretty straightforward and easy to understand.
There are two types of any Xcode project structure organization:
filesystem project structure (inspectable with Finder.app)
IDE project structure (inspectable with Project Navigator in Xcode's navigator area.)
Xcode relies on filesystem organization by keeping a reference to a "physical" file or folder. That is why you may have all the classes, images, plists, and other parts of your projects stored in the same folder, while the references to these parts are being kept organized into respective groups within Xcode project.
When you create a group, it affects the organization of your project in Xcode. When you create a group with a reference folder, it creates both, a group in Xcode project and a folder in your filesystem.
However, since Xcode 9 it seems like, Apple enforces filesystem project structure to correspond to Xcode project structure. It means, that you explicitly has to choose "New Group without Folder"
Added files and folders from Finder into the Xcode group. Xcode 10.2.1. Just take a look at the examples without Copy items if needed
Files
Common behaviour for create groups and create folder references
Rename a file from Finder does not rename the file in Xcode, as a result Xcode doesn't handle it and it will mark them by red color.
Rename a file from Xcode rename the file in Finder
Change a file from Finder change the file in Xcode and vice versa
Remove to trash a file from Xcode change the file in Finder and vice versa
Add a file from folder in Finder does not add the file to group in Xcode
Folders
Common behaviour for create groups and create folder references:
Rename a folder/group from Xcode rename the folder in Finder
create groups
If you choose create groups, then the corresponding folder appears with a yellow icon in the project navigator.
It is just a virtual folder. It useful during development when you copy a file and it is not compiled and you do not have a time to make changes in it and want only to check if a project works. So you can just remove a reference from a file. It will not be removed from a folder as a result you will be able to add this file again.
Rename a folder in Finder does not rename a name of group in Xcode. You steal can work with group but previous content inside although visible but unavailable
Add a file to a folder in Finder does not add the file to group in Xcode
Add a file to a group in Xcode does not add the file to folder in Finder
Remove a folder in Finder does not remove the group in Xcode. You steal can work with group but previous content inside although visible but unavailable
create folder references
If you are choosing create folder references, then the folder appears with a blue icon in the project navigator.
It is a real folder and any changes will be reflected
Rename a folder in Finder does not rename a name of folder in Xcode. The previous content is gone and you can not work with this folder
Add a file to a folder in Finder adds the file to folder in Xcode
Add a file to a folder in Xcode adds the file to folder in Finder
Remove a folder in Finder removes the folder in Xcode.
[Copy items if needed]
Create folder references:
Useless because even if you list this folder to be included with a target, Xcode won't include any of its contents in that target and there's no way to click on something in the folder and see which targets it's included in.
Create groups:
This is the only way to go, if you want to include any of the folders' contents in a build target.
When I am adding a new folder, that i took from another project, to my Xcode project (which has many subfolders and classes in it) it creates this folder with a gray color and not the yellow one as the rest of my project's folders.
Then when I am trying, from another class in my project to #import class.h that is in this folder, I get an error saying Xcode doesn't see it in the project.
class-name file is not found
I have added the folder using "Add files to project-name".
What am I doing wrong?
A gray folder is a reference to a folder on disk, whereas a yellow one is a group representing a collection of files in a project. For most source code, you'll want to use the yellow kind. To do this, when you add the files to the project make sure that you use Create groups for any added folders as opposed to Create folder references for any added folders.
This is probably a very easy question, but I'm having trouble deleting resources from my XCode project. I added them using "Create Folder References for any added folders" so that I could import a whole offline HTML site with its correct folder structure.
Unfortunately, now it has been added like this I don't seem to be able to delete individual files in the structure (it's not available from the Edit menu).
Can anyone help please? Thanks!
That isn't how folder references work. The idea is that its only a reference, you can open files within it and save it from those editors, you can delete or move the entire reference throughout the xcode project, but you can't actually edit it - its read only as far as xcode is concerned. Likewise, you cannot restructure it (move internal files around).
I'm not to sure why apple decided to make this the case, but apparently they have.
If you want to know how one might use the xcode folder system, here's how I tend to use them with my projects:
Whenever I subdivide code into folders, when I drag them into my project I click "recursively create groups for any added folders". If you do this, you any changes you make within xcode will not reflect the actual file itself. As far as I know, there is no way to do this. What does happen then is that when you add a new code file to it, the directory starts off in that file by default. ie, you don't need to navigate to it manually when you create a new file.
I use folder references whenever I'm working with content for an application I'm using. This way, I add all my images, folders, configuration files, whatever - and xcode immediately lists them. The reason I have it within xcode, I can I copy the files into the executables directory by dragging the folder reference into a "Copy Files" build phase.
Thats basically (to my knowledge) how one uses the folder types within xcode - sadly, I don't know how to achieve the functionality you want. You may have to manually delete the folders in finder, which if you do use folder references will update xcode to the change.
I ran into the same issue by using "Create Folder References for any added folders". I wanted to change some of the times but that's not possible. I had added a main folder that had other directories under it. I just had to select the main directory and deleted it and then just add the subdirectories that I needed. You can't make any location or removal changes to the directories that are added this way. -- Jeff
In the project browser, where you're looking at files, right click and choose "Delete". It'll prompt you to either remove the file from the project (leaving the underlying file on the filesystem) or to also move the underlying file to the trash.
I ran into the same issue. Delete the files from the folder directly as opposed to from within Xcode. You'll see the entries turn red under your project. Restarting Xcode should make these red entries vanish.
I have read all the suggested StackOverflow posts on this question. It bothers me that Xcode will not organize my files in the finder the same way it does in the editor view...it will only do that if I copy files in from an external source and specifically tell it how I want things organized. Is there a way to make Xcode have the Finder respect the same organization as a default? I'd love to create a directory and then a file in that directory, and see the changes in both places.
I hate opening a project and seeing ALL my files in one place.
If you want your Groups structure in Xcode to mirror your Directories structure in the file system (which is also the Folders structure in the Finder), you have to take the following steps when adding files that you want to go into Groups/Subdirectories:
Create the folder in the Finder (or the directory from the command line)
Drag that folder into your Xcode project. Import it as a Group. Make sure its reference style is Relative to Enclosing Group, and that you drop it into the Group that represents its parent directory.
To add new files, select the Group and choose Add Files. The files will be stored in the directory that that Group represents, and they will be within that Group in the Xcode UI.
If your files are not yet under SCM control, one thing you can do is just delete them all from the Xcode project, rearrange them on disk however you want, then drag all the folders and files back in, making sure to not make copies, to create groups, and to set the reference style to Relative to Enclosing Group.
I have a Visual Studio 2008 solution, and I would like to include a real folder in the solution, but not at the project level, instead at the solution level.
I noticed you can right click the solution and add a solution folder, but it comes up as some white folder, and I have my doubts as to exactly what it is supposed to be...
Basically on the file system I have c:\mySolution\myFolder...
I want that myFolder is added to the solution, so that items are also under source control...
I also would like to be able to add physical folders to a solution, but unfortunately you can't do so outside a project.
The best solution I have found is to add a solution folder with the same name as the physical folder (myFolder in your example), then add files from that physical folder to the solution folder.
However Visual Studio does not maintain a mapping between the solution folder and the physical folder which means that:
new files subsequently created in the solution folder using Visual Studio are not automatically placed in the physical subfolder (I think they are created in the solution root folder by default)
files added to the physical folder are not automatically visible in the solution folder, even with "Show All Files".
To add new files, I therefore always create the new file in the physical folder outside Visual Studio, then add it to the solution folder using "Add/Existing Item"
What I have done historically is to create a project for just holding files (DLLs, etc.)
You can do that as well. This project can be named as whatever folder you are trying to create.
Follow this...
Create the solution folder from Visual Studio.
Right click the solution folder to create a new project.
Change the default location path to add the new physical folder name right after it with the back slash. Something like...C:\Project\Test\New Physical Folder
Click the OK button to create the project
Then the new project will be put inside your new New Physical Folder.
You can also add standalone files in a solution folder, and they will be source-controlled. But be wary that VS tends to put these files in the same folder as the solution file - the "Solution Folders" are virtual and don't corresspond to real filesystem folders. To have a real filesystem folders I think you would have to create the structure yourself and then choose "Add Existing Item".
From MSDN:
"If you are working with a solution that contains numerous projects, you can use Solution Folders to organize related projects into groups and then perform actions on those groups of projects."
You don't want what the composer meant in Solution Folder. It made them to organize large solutions into groups.
For your problem, I think this is the job for your Installation Project to collect these files: Installation instructions, Global help, etc...
You can use a solution folder to group files in a solution, but a solution folder doesn't represent an on-disk folder, like its logo suggests. (It can contain file references and project references.)
My prefered solution is to add a Shared project, which is like a folder but with a special icon.
Create your Solution
dotnet new sln -n demoProjectName
e.g. Your solution folder path C:\Projects\demoProjectName>
Create a Project within the same solution Path
dotnet new classlib -n Persistence
From your solution folder path, do this
C:\Projects\demoProjectName> dotnet sln C:\Projects\demoProjectName\ add C:\Projects\demoProjectName\Persistence\Persistence.csproj
Please note: Persistence as used is just a placeholder for your project name. classlib for classLibrary projects and it could be a console project and so on.