Xcode 4.2 how include one project into another one?
Asked Answered
D

6

80

I keep searching, but cannot find a clear and simple explanation on how to include one XCode project, along with all of it's sub-classes into another project. I routinely see stuff like that in sample projects that I download off the web, but do not know how to do this myself.

Within XCode, along with .h and .m files, and folders, there's a whole new project, starting with a blue xcode project icon, that is expandable to contain everything within the project.

Please, can someone explain to me step by step what do I need to do to add one XCode project into another one? I've seen a ton of one liners like "header search paths", but that does not tell me much.

UPDATE: After re-reading the documentation, I realized that the project to include must be dragged ONTO the BLUE project icon of the parent project. Regular sources can be dragged anywhere, but a project must be dragged onto a project.

Thank you!

Differential answered 21/2, 2012 at 0:35 Comment(0)
C
145

This makes a lot of sense when you are trying to add a static library to your xcode projects. There are a couple steps required for doing this. First, make sure that the static library project is not open in XCode.

Then start by dragging and dropping the static library xcodeproj file (from the Finder) onto your app's xcode project. StaticLib

After this you need to add this library to your app's build phases. Click on the main project, and select the BuildPhases tab of the target.

Build Phases

You're going to want to add the other project to the Target Dependencies and to your Link Binary With Libraries Section.

Finally, the app needs to be aware of your headers. Therefore, you need to add the path to your static libraries classes to your User Header Search Paths. Go to the Build Settings of the Main Target and search for Header Search Path.

Header Search Path

This will make your app aware of the new static library.

Sometimes you need to add a few Other Linker Flags. In the Build Settings search for Other Linker Flags and add -all_load and -ObjC

Other Linker Flags

Chromophore answered 21/2, 2012 at 0:48 Comment(8)
If this Post was helpful, please mark as the answer. :) let me know if you have questions.Chromophore
Important detail, guys: The project you're dragging shouldn't be open in Xcode. In case anyone faces the same issue as me. :)Darkish
@Chromophore would you be able to update this post? Your instructions are very helpful but don't seem to be accurate for XCode 6. When I search for User Header Search Paths in the Build Settings I can only find "Always Search User Paths"Alan
@Alan You need to ensure that you are showing "All" options in the build settings instead of just "Basic". You might be set to basic. I'll go through and update the screen shots.Chromophore
@Alan I just using this instruction to import an external project into my project. XCode 6.3. Works perfectly. Thanks for a clear instruction, MobileOverlord.Brinn
@Chromophore you were right I needed to show "All" options.Alan
@Chromophore How would you keep the header paths relative, if you were to share this on a repo with other developers?Ignitron
Don't forget to set the path to be recursive (option in the right-hand column if you double-click the path row)Puzzlement
C
7

Make sure the project you want to add as subproject it's not open, before you add it or drop it.

Cydnus answered 8/2, 2017 at 19:31 Comment(3)
Thank you! This was a life saver for me.Sucking
@VibhorGoyal You are welcome, I also struggled with this some time ago :).Cydnus
In addition, make sure that you don't have another Xcode project open that also uses your desired subproject as a subproject. This is the same as having the subproject itself open, and will prevent the process from succeeding.Eldred
O
4

You can just drag-and-drop any xcode-project file (*.xcodeproj) into the project navigation pane of your desired parent-project.

You then may need to add target dependencies, depending on your needs.

Is that what you mean?

Onia answered 21/2, 2012 at 0:39 Comment(3)
Part of the reason why I'm asking is because I tried dragging the .xcodeproj over, and it did not copy all the subfolders. Worse yet, when I tried to remove the .xcodeproj to try to drag it again, I accidentally deleted the .xcodeproj from disk! That was a fun day.... notDifferential
That's because a XCode project stores references to files, not actual copies. That's why deleting your file actually deleted the original file from disk. And since only references are stored, subfolders aren't necessarily copied (only if they are referenced in the project).Onia
Alex, start using github, or some svn service. That way you do not lose and can play around.Haematocele
Z
4

Make sure to choose "create groups" instead of "create folder references". If your folder is blue instead of yellow, then you have a folder reference. The folder should be yellow.

Zizith answered 15/2, 2016 at 22:24 Comment(0)
E
1

drag and drop xcode file to another xcode file from finder. It will ask you for copy the file then check the check box and it will copy to your project.

Ellingson answered 27/8, 2013 at 5:22 Comment(0)
Q
0

You have two variants to add source code into your project:

  1. Explicit dependency[About] via creating target dependency with a cross-project reference[About]
  2. Implicit dependency[About] if the source code is a part of the same Workspace[About]
Quincyquindecagon answered 25/9, 2019 at 10:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.