Xcode does not recognize a folder I've added from another project - xcode

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.

Related

Create groups vs Create folder reference in Xcode

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.

Changing the name of main folder in Xcode project

This is not the first time I've had trouble with this and I suspect not the last time either. Despite having learned many frameworks inside out I still find the organizational structure of a simple xcode project elusive. I simply wanted to retitle a project from CATouchSynth to ABTouchSynth. A while ago I discovered that if you click on the Project folder in project navigator and than change the name in the Identity and Type section it will rename many of the relevant files and directories to the new name. However, there is one main folder inside the folder on your computer that doesn't change and still has the old name. I could see no way to change this folder name through Xcode and so I renamed it manually from finder. This turned all of my source files and assets red so I manually "relinked" them in xcode and they are now non-red and seemingly linked with the newly named folder. However I am getting several compile-time errors talking about the old folder name but I have no clue what Xcode is referring too. The errors look like this
It seemed as if derived data was an issue so I deleted the derived data folder from Xcode and I still get these errors. Has anyone experienced this before and what can I do to ressurrect my project?
Note: Before doing any changes do backup your project folder. This is seriously recommended.
Follow the steps below to rename the source folder of your project –
Close XCode.
Rename the Source Folder.
Right click the project bundle .xcodeproj file and select “Show Package Contents” from the context menu. Open the .pbxproj file with any text editor (Xcode).
This step should be done with extreme caution. Search and replace any occurrence of the original folder name with the new folder name.
Save and Close the file.
Open XCode project.
The error is happening at build time during the compile phase, so you will have to go into the app target's Compile Sources build phase, remove all those .m files, and add them again.

How to create folder within project

I want to have all my image files in a folder so that I can obtain all of them at the same time. I think the path should like this ...MyApp.app/image folder/1.png.
But when I drag them into xcode with folder references created, there is no folder. The path is always MyApp.app/1.png.
Also, I think I've dragged the files into the app several times. How to delete the files? It's not enough to just delete the references.
If they are not visible in project navigator, that means that you have no references to them and you can delete them directly in finder.
You are likely to have moved every image to a group rather than a folder. A group is just a convenience in Xcode project navigator. It has nothing to do with file hierarchy.
To keep them in a folder, right-click project navigator. Select new folder, drag your files to that folder. When they are visible in your project navigator, make sure that they are all linked to your project. I.e they are all check market with your project in the right pane.
It important to drag them to the folder and not just outside of it.
Here's the easiest way to do this in Xcode:
1)
Put all your images into a folder and then drag that folder into the list of files in your Xcode project. That step looks like this:
2)
A sheet will drop down in Xcode and ask you how you want to add these files to your project. It looks like this:
There's a checkbox at the top there that says "Copy items into destination group's folder (if needed). You will check this if you want to copy your folder full of images into the same place where your source code is found in your Xcode project.
3)
When you're done adding, here is what your project should look like in Xcode. Notice that the folder color is blue. That means it's a folder reference. This folder will be copied into your built application.

Xcode, add folder to project that retains directory structure and update automatically

I have folder that I would like to include in my Xcode project, but I would like it to retain it's structure (subfolder, etc). When I drag it into the resources in Xcode it expands that folder into a group in the Xcode project.
I would also like it to retain it's structure so I can add and remove files without re-adding the modified folder to the project constantly.
When adding your package, select the option to "Create Folder References for any added folders". Xcode will create a reference to the directory, and notice changes every time you rebuild the package.

How to map groups in Xcode the same on the filesystem

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".

Resources