Merging two Xcode projects... Workspaces / Schemes? - xcode

I have two projects. One is written in Swift 3, while the other is written in Objective C. Both compile and run fine.
I have tried to add the Objective C project into Swift by adding files to the project. The project won't build because it can't import the bridging header. I have spent two days on this and am certain that I am correctly specifying the location of the bridging header and header files under build settings. I'm now looking for an alternative approach to merging these projects.
From Apple: In addition to organizing all the files in each Xcode project, a workspace provides implicit and explicit relationships among the included projects and their targets.
Does this mean if I add the two projects to a Workspace that I can build the two targets into one target resulting in one product? I read something about using schemes, but the post wasn't detailed. I'm running Xcode 8 and Swift 3.
Thanks.

Workspace is used to maintain multiple projects in single space.It wont merge two projects and create a single target/product.
Simple way to add bridging header, create a new ObjectiveC/Swift file in the project will prompt "Would you like to configure an Objective-C bridging header?" dialog by xcode, will automatically create the "yourprojectname-Swift.h" file for you.

Related

Change Default Framework List of a Xcode Project (Link Binary With Libraries)

I am creating so many new projects on Xcode in a day. I got tired of putting necessary frameworks for each project every time.
So can we change the default framework list in Build Phases -> Link Binary With Libraries?
If it is possible, can we also add frameworks to that default framework list from outside of Xcode?
For example:
I couldn't find a direct solution to edit default framework list of Xcode, but a temporary solution that I found is to edit Search Paths under Build Settings

Create "Template" XCode project that automaticly adds git-submodules etc?

I have a few xcode projects (static libraries) that I include in several other projects through the use of git-submodules. This works great and I like this way of sharing code between projects. However, since I am adding some of these libraries to pretty much every new project I create I would like to streamline this process somehow. Create some sort of "template" of which I can base all my projects.
I would like some way to automaticly go through these steps:
Create a new project called X
Add a fixed (or dynamic) list of submodules
Have the added submodules automaticly added to the Xcode-project
Is it possible to create a script for this? With a syntax like:
fooproj -n "Bar" -s "foundation, coredata, uikit"
(where Bar is the name of the new project and foundation, coredata and uikit would be the submodules to add)
Or is there some other way I could streamline this process?
Have you looked into Xcode Templates? They're quite powerful and are the basis of how Xcode currently sets up new projects. Here are a few links on how to create Xcode templates:
NSScreencast, bob Mccune's blog, meandmark.com
And a few sample resources to get you started:
Xcode 5 project templates and Minimal templates
They're confusing at first, now I couldn't live without them. Xcode templates are a huge time-saver.

What are "targets" in Xcode?

I have seen a lot of things about 'targets' while working with xcode. when i click on the project icon (blue, in xcode 4.2) i see 'Targets' in the middle pane with my file name under it.
What does that mean? and can I add more 'targets' to my project? If yes, what would that mean?
I have this:
http://developer.apple.com/library/ios/#featuredarticles/XcodeConcepts/Concept-Targets.html
but i didn't understand a thing
A target basically defines what it is you are building and how you are building it. You can add more targets if you would like to build more than one thing. This usually makes sense if you need to build several related things from the same project.
For instance, you might want one target for a full, paid version of an application, and another target for a reduced, free version of an application. Both targets would include much of the same code and resources, but some of the settings would be different and you might have different files included with each.
Targets are simply different ways of building a product. You have your source files, and you have your output, and there are several ways that you can get from A to B.
An Xcode project may contain a number of source files which can be built do produce a number of different products.
For example, you could build an executable using some of the files, or you could build a library (Framework) from some of the files, or a unit test library, or with different build flags.
Most projects will have a single target, but some are more complex than others.

XCode 4.2 and Using a Static Library Causing Problems

Like many others here SO, I am having issues using libraries in my XCode workspace. The idea is I have my main project (MyApp) and two libraries (lib1 and lib2) which were added to the workspace after the code was finalized.
For background, lib1 is dependent on lib2, since there are some protocols that need to be implemented in order to make use of lib2. MyApp is dependent on both. I have tried following the Apple guides, which implies what I would like to is simple. After that, I have followed pretty much every post here on SO that has come up in my searches (2 days worth of Googling), plus many other blogs and posts that claim to have solutions, many of which are XCode 3 specific.
Yet, my project does not build. I am using Xcode 4.2 on OS 10.6 (upgrading to Lion is not an option). Is there a simple tutorial to follow on how to create a library project, and use this library in an application.
I came across this answer while writing this question (where the question had the same error I had), which I will look into, but I have reached the point of copying source files over just to get a demo working.
UPDATE:
Here is list of issues that have come up. I will add more when they arise:
**directory not found for option '-L/Users/myhomedir/iphoneprojects/MyApp/../BLProfile/build/Release-iphoneos'**
Here is how to create a static library and a project that use it.
Step 1: Create a workspace: File > New > Workspace. This is not mandatory but it helps organize the projects.
Step 2: Create a static library project: File > New > Project > Framework and Library > Cocoa Touch Static Library. Lets call it MyLib.
Step 3: Create an Application Project: File > New > Project > Application> Empty Application, or any other application template. Lets call this project MyApp. If you placed the projects in different folders, you may have to use a different path.
Now you have the following Projects in the workspace.
Step 4: Configure the app so that it finds the .h files of the library. To do that, add the parent folder "../" and check the recursive checkbox.
Step 5: Link the app to the library.
Open Main Project where you would like to add static library.
Save as workspace.
Add library's project package. No need to check copy while adding project package.
Update Xcode preferences location to Custom-Relative to Workspace. Products as 'Build/Products' and Intermediates as Build/Intermediates
In your Main project -> target -> build settings, Add Header and Library Search Path as $(BUILD_PRODUCTS_DIR)
Build Library Project. So a new library will be created in mentioned build path.
Remove existing library from Build Phases and move to trash. Open Build Phases -> Link Binary With Libraries and add newly created library from build directory.

Xcode 4 and nested projects -- header files not found

I'm having a myriad of problems with Xcode 4 and nested projects that worked just well under Xcode 3.2. Here's a very basic one I cannot solve:
I'm building a cocoa framework that requires another cocoa framework for which I have the source. So I perform the usual steps:
Drag the .xcodeproj file of the required framework into my main framework project
In my main framework under TARGETS > MyFramework > Build Phases > Target Dependencies: Add the nested project's target
Make sure the header files of the nested framework are public
In Xcode Settings > Locations > Build Location I have it set to Place build products in derived data location (recommended)
Build products path of both targets are set to ${BUILT_PRODUCTS_DIR} and tell me they are at the DerivedData/Debug (or Release) location
Architecture settings for both targets are identical
Then I hit [CMD] + B to build and it tells me that it doesn't find the header files of the nested framework. When I check the settings, User Header Search Paths contain the path to DerivedData/Debug, and inside there is the nested framework target with the header files in Versions/A/Headers.
I'm sitting here, anybody an idea what I'm doing wrong?
The issue goes away when building for Debug when I change the User header search paths to ${BUILT_PRODUCTS_DIR}/MyFramework.framework/Headers. However this doesn't work when building for Distribution as the frameworks then use their Release settings, which ends up in a different subdirectory...
My temporary solution is to also define a Distribution configuration for the nested projects. This way the headers are found and the linker can link successfully.
Here's my synthesized knowledge so far:
Forget the whole public header thing with Xcode, it's a PITA and doesn't work correctly when archiving your app. Instead, have all static library header files on the project level and tell your app where to find it.
Ease your pain by making sure all targets have the same name for the build configuration (i.e. add an "AdHoc" and "Deployment" configuration to the static libraries).
In build settings, point the Header Search Paths (if you use #include <file.h>) or User Header Search Paths (if you use #include "file.h") to the directory of the static library project. If the static library project is inside your app directory, use this:
"$(PROJECT_DIR)" (recursive enabled)
If you have a directory which contains a) the static library project and b) your app, then this should work:
"$(PROJECT_DIR)/.." (recursive enabled)
If the submodule contains compiled libraries, set your Library Search Paths to:
"$(TARGET_BUILD_DIR)"
Make sure all the static library projects that you use have Skip Install set to YES.
Again, no public header files (Build Phases » Copy Headers) in any of the static libraries, otherwise Xcode will not be able to archive an app.
Make sure to tell Xcode when to build the static libraries, as shown in this Tech Doc from Apple.
Old Answer:
I still haven't found a real solution to this problem with static libraries. What works for me is:
Create an "AdHoc" Configuration for the static library
Add $(BUILT_PRODUCTS_DIR) to User Header Search paths for the application (with recursive checked) -> this is used when running the app
In the Xcode menu, select Product > Build For > Build For Archiving
This works, the app finds the header files and builds itself, it ends up in DerivedData//Build/Products/AdHoc-iphoneos/ as an App bundle. Following these simple instructions (dead link) from TestFlightApp.com I can pack this App into an IPA and send it around. Simply selecting to Archive the app from Xcode does again not find the headers, even if they truly are in the AdHoc-iphoneos build directory.
(As of Xcode 5.1)
When the subproject is built by XCode, the subproject header files are copied into the build directory. When archiving, it seems that this copy destination directory is not added to the header/include search path. You'll want to go to your Build Settings and add
$(BUILD_ROOT)/../IntermediateBuildFilesPath/UninstalledProducts/include
to the "Header Search Paths" for the scheme that you use for archiving.
If you're not sure which scheme is used for archiving, go to Product -> Scheme -> Edit Schemes and look for Archive in the left column.
Make sure your third party framework is added as «group» to your main project, so you can see it in your project's hierarchy...
I had the same problem here and I could solve the problem by setting "Build Location" to Place build products in locations specified by targets"
I had this problem: I could build both Debug and App Store configurations, but not Ad Hoc. Building Ad Hoc gave me errors because it couldn't find .h files needed by nested projects.
Turned out I had an expired provisioning lingering in my Release configuration. I updated that provisioning link and now I can both build Ad Hoc and use the Archive feature to package it.
Took me hours to figure it out! My mind just didn't jump from missing .h files to provisioning errors just by itself. =) There might have been an error or warning complaining about the missing provisioning, but if so it was well buried among the hundreds of .h related errors.
I was having the same issue with a Configuration named "Ad Hoc" (as per TestFlight recommendation at http://help.testflightapp.com/customer/portal/articles/402782-how-to-create-an-ipa-xcode-4) and the main project could not find some of the headers from the nested projects. I renamed the project to "AdHoc" (no spaces) and the problem went away; seems like spaces can mess up header search paths in some cases, although I haven't figured out the specifics of when that might happen and why.
I was having this issue with a nested project that built a static library. I found this doc on apples site that completely saved my life.
http://developer.apple.com/library/ios/#DOCUMENTATION/Xcode/Conceptual/ios_development_workflow/AA-Developing_a_Static_Library_and_Incorporating_It_in_Your_Application/archiving_an_application_that_uses_a_static_library.html
I'm so glad I didn't have to muck around with the derived data paths.
For me, this happened after a GIT merge, which created many conflicts, one of them related to the project file. After the merge, I'm sure the structure of the project file changed.
What I ended up doing was going into the project "Build Settings", then looking for "Always Search User Paths" and turning it to Yes.
I guess the merge turned this boolean to No, therefore the project wasn't looking in the right places for the header files.

Resources