Not sure if the existing answers help you. I'll just give my solution. First, I want to explain several important Build Phases.
Target Dependencies
If you want to rebuild your own framework (which you linked to the same workspace) every time you build your host app. You'll need to added the framework target here.
Link Binary With Libraries
If you want to use your library in your code (say you want to do import MyFramework
), then you need to linked it in this phase.
Embed Framework
This is the tricky part. Embed means to bundle the framework together with your app when distributing. For a system framework, such as AVFoundation
, you don't need to embed it into your app since it already exists inside the iOS operation system. However, for your custom frameworks or third-party frameworks, you'll have to embed them into your app bundle so that when you deploy your app on the device, the app can actually find it. That's why if you use Cocoapods
or Carthage
, they all have an extra build phase to copy the frameworks to the app bundle. (For Cocoapods
, it's called Embed Pods Framework and for Carthage
, it's an action that runs copy-frameworks
script) So for your custom framework, you'll either use the existing Embed Frameworks
build phase or create a New Run Script Phase to copy the frameworks to your app bundle.
-- Update on 2017-05-17 --
For the embed framework stuff, there's another important fact I found recently:
You can use file PATH/TO/Framework
to check whether a framework is static or dynamic. Check this stackoverflow question for details.
Dynamic Frameworks
Only dynamic frameworks need to be embedded into the app. These include the ones created by Carthage
and Cocoapods
. If you open the app bundle after you build your project, there's a Frameworks
folder that contains all your embedded frameworks and you'll find the ones created by Carthage and Cocoapods as well as the ones you specified in the Embed Framework phase.
Static Frameworks
So now you might wonder where are those static frameworks? How can we still use it if it's missing from the app bundle? You're right. They are in the bundle but not in the Frameworks
folder. They have been merged into the executable of your app. If you check the size of executable, you'll realise every time you add a static framework to your target, it will increase.
Static frameworks don't have to be embedded (just Link them), it's like a .swift
or a .xib
file that will be compiled into your executable.
And then, there's one more step to go before you can use any framework. The Framework Search Paths
inside target Build Settings. Again, if you look at Carthage
or Cocoapods
, they all add extra paths into this setting. This tells Xcode (or the underlying compiler) where to find these linked or embedded frameworks.
So every time you'd want to use a framework, make sure you think about the above settings and you're all set. I've been using this method for a while and feel more confident when I encounter any linking issue.
Finally, there's a very important article from Apple you should read https://developer.apple.com/library/content/technotes/tn2435/_index.html