Header search paths for subproject in XCode - ios

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.

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.

Xcode source path

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.

Adding a dependency to a repository with Xcode 6.1

I'm new to programming on iOS and I'm running into a roadblock with adding dependencies to my repository.
When I drag and drop a framework into the project directory and reference everything, I can build the project no problem. The issue is when I commit my project to the repository, the framework files do not get copied over. I can see that they are located in their original directory in some other location. Xcode merely references these files instead of adding them to the project directory.
So my question is, how do you add a framework or dependency to a project directory and commit it alongside your project to your repository?
Note I'm using SVN, however a Version Management System agnostic solution works for me.
In your case, or most cases people just download the framework and add it from there directly though it works in their machines, but will not work in other machine, because of absolute path added to the Header Search Paths settings in Build Settings.
In case of Third Party frameworks are as follows, will work for any case. Add the relative path rather than absolute path, though you don't set it, it is automatically added while you add a framework. So what are the steps? See below
Step 1
Create a folder named framework inside your svn/git folder of your project, and put all the frameworks inside the folder..
Step 2
Now add the framework, from the framework folder as you were doing earlier.
Step 3
Check your Header Search Paths in Build Settings. You will see entry for your framework header path. It should look something like
/Users/username/ProjectFolder/Project/frameworks/myframework/framework.h
Change the above entry by
$(SRCROOT)/frameworks/myframework/framework.h
Doing the above will automatically change this /Users/username/ProjectFolder/Project/ part of your path according to any system you clone the project. And it will work automatically.
Note - Before performing the steps, remove all old Header entries, which has absolute path.
Hope it helps.
Cheers.

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

iOS: Clarify different Search Paths

There are three different search paths in XCode Build Settings:
Framework Search Path
Header Search Path
Library Search Path
Could anyone clarify what those paths do and what they are used for?
Framework search path: where to search frameworks (.framework bundles) in addition to system frameworks paths. Not used very much in iOS development, officially there is no developer iOS frameworks.
In Mac development, it's set automatically if you drag a 3rd party framework into the project. Otherwise, just set it to the container directory where you saved the framework.
In xcconfig files you use this variable:
FRAMEWORK_SEARCH_PATHS = "/path/to/frameworks/container/directory"
Header search path: where to search for header files (.h files) in addition to system paths. Usually you'll need it if you are using a 3rd party library. Set it to the directory where you have the header files. If you use a directory to include the header (example: #import "mylibrary/component.h") set it to the parent directory.
In xcconfig files you use this variable:
HEADER_SEARCH_PATHS = "/path/to/headers/container/directory"
Library search path: where to search for library files in addition to system paths. Xcode will set it automatically if you drag a library (.a files) into the project. To set it manually, use the directory where the library is located.
In xcconfig files you use this variable:
LIBRARY_SEARCH_PATHS = "/path/to/libraries/container/directory"
All three can hold a list of paths, with quotes, separated by space.
These are used for searching for Frameworks, Header files, or Libraries that are not in the system search paths (like QTKit.Framework, standard C++ header files, etc).
My most common use for this is using the boost header library (*.hpp) files in my code I add the relative path "../lib/Boost/1.46.1" to the Header Search Path.
I find it better to add this at the project level instead of in each target. That way the targets inherit this and it only needs to be changed in one place if I update the version of boost.

Resources