Xcode source path - ios

I'm working on a project with Xcode, and I'm rearranging all the source files. I see that Xcode, in the "Compile Sources" section in the target configuration, looks for all the source codes using a pathname relative to the project directory (PROJECT_DIR).
I have created a new folder where all the sources, libraries, and headers will go. Is there a way to tell Xcode to look for sources from a user-defined directory so when I change the directory I won't have to re-add all the source files?

You can use Xcode file inspector to modify the path. Here you can change the path of groups and file in your project structure.
Make sure all your files & groups are set Relative to group.
This way when you move files in group to a different location keeping their relative positions same, you can just change the group path from Xcode.

Related

How to hide path inside Swift Package from Project Navigator managed by XCode?

I've created Swift package, which contains a folder with an example project. Its path is not included in any target sources. Nonetheless, after opening Package.swift file in XCode, Project Navigator still shows not included paths. How to hide that obsolete folder?
As I suppose, it is unlikely that XCode manages Navigator contents using an exclusion path from target configuration. It shows not only files specified in targets but all files included in root path. It is reasonable because the package can contain a readme file that can be edited by XCode, however it is not reasonable for files of the example project.
You can make your folder hidden in your Swift Package by adding . at the begin of its name and the Project Navigator doesn't show it because by default, folders with periods at the beginning of their names are hidden in OS X and XCode as well e.g.: .RxStormExample.

Whats the best way to add a dataset of 50 Folders to an iOS App?

In my case I have 50 Folders where each of it has subfolders and images. I could drag them into the apps main bundle but there are many duplicate filenames and it would be more practical to access them in the structured way.
Your wording "it would be more practical to access them in the structured way" seems to suggest that you think the Resources folder cannot contain a folder tree of files, it can. However if you let Xcode itself copy your resource files into the bundle it will flatten the tree without any option to preserve it (for reasons unknown). To address this you can copy the files into the bundle using a build script.
In outline, you need to fill in the gaps with some reading:
First add your files and folders into your project. Use one group per folder, in Xcode 9 creating a group creates a corresponding folder in the project directory but in prior versions you must create the group and then associate it with a folder – check the documentation of whatever Xcode version you are using.
Mark all the folders and files added in this way as not part of your build target. This prevents Xcode copying the files automatically into the bundle, and flattening your folder tree in the process.
Now in the target settings go to the "Build Phases" tab and add a new build script phase. Add a shell script which uses something like ditto to copy the folder tree into the bundle. Various environment variables are set which reference the project and the bundle, check your Xcode documentation or just run a dummy script and dump them out (it is an option, or use printenv). You can use these environment variables to determine the source and destination for your copy.
In your app itself you can locate the root folder of your tree using standard bundle methods. From there you can use whatever method you choose to traverse it/reference items with in it, in exactly the same way you would if the folder tree was not inside the bundle.
HTH

Header search paths for subproject in XCode

I added a subproject (a library) to my project.
In order to be able to import the header files of the subproject, I'm adding the absolute path to the subproject directory (recursive) to the "Header Search Paths" of my main project. Is there anyway to configure XCode to automatically/ dynamically recognise the path to my subproject directory?
I feel that what I'm doing right now is very manual and prone to human errors. Also, in case I moved my subproject, I will not be able to import its header files anymore.
Note that I don't want to put the subproject directory inside the same directory with the main project as it will be reused for many different projects.
The reason why I expected this functionality of XCode are:
XCode allows me to drag and drop my library project into the main one, which is an intuitive and dynamic way of including library. It should not, therefore, require me to manually put in the path to the main project's build settings.
When we drag and drop our files and directories into an XCode project, it seems to handle the XCode's references and the filesystem paths smoothly. I don't understand how the logic differs for header search paths for subprojects?
You can use a relative directory, as opposed to an absolute directory, by using $(PROJECT_DIR), which is one of Xcode's many variables.
Assuming the sub-project is in a sibling directory to the app project (a system I use myself), then set Header Search Path to (something like):
$(PROJECT_DIR)/../libproject/include
This will allow the project to exist anywhere in the filesystem, provided the project directories maintain the same relative path to each other.

Moving files around in XCode and IOS 7

I move some files into a subdirectory but now I get linking errors saying files can't be found. Where do I go (like a projects file) to tell XCODE where to look for the new files?
I tried removing everything and adding them back in but I still get missing files even though they are one directory in and added to the project.
Select a file in left panel, open inspector panel on the right and choose a path to file there.
Note: it's more efficient to do that if your files are organized into folders; that way, you only need to change the path to folder and the elements are relative to it.

Adding frameworks to project in Xcode 5 and having *relative* paths added

All of a sudden today I get an unexpected problem with Xcode (5).
This is how I normally add an external framework:
Drag-n-drop the file (xxx.framework etc) (or the folder which contains the file) into the project manager.
In "Choose options for adding files" I check "Copy items into destination (if needed)" only if needed (if the files are already in the project's folder I don't do this)
In "Folders" I select Create groups for any added folders
And I add it to my app target.
Normally this would also add the relative path(s) to the framework in Build Settings/Framework Search Paths and Library Search Paths.
However today the path that shows up there is direct (aka absolute). This breaks stuff down the line because the paths should be relative. How come Xcode does this all of a sudden? I suspect it might have to do with this one project only (it comes from a 3rd part dev) and something about their project setup could be causing this.
I faced the same issue. There is a simple fix. Go to framework search paths. Remove everything from there. Add ./ and make it recursive. That's it.
I am having the same problem on XCode 5, so far the best solution is to modify the path of your framework search.
Go to your project
Build settings->Framework search path
Add the relative path to your framework.
If it was correctly copied now you can modify the path, to something like this:
./MyProject/Libraries/ACoolLibrary
Supposing a file structure like this:
-MyProject.xcodeproj
-MyProject
--Libraries
-----ACoolLibrary
-------- TheCoolLibrary.framework

Resources