The Lost art of adding 3rd party frameworks into your project
Cocoapods has been the leader in dependency management since iOS5. Once you use it you would never go back to the “old” way of doing things.
Ever since swift came out, Carthage has been the cool kid on the block and showed us that there is another way to do dependency management.
However, there are some folks out there that are worried that a 3rd party framework might suddenly stop working or stop getting maintained. In these situations it is good to go over the old fashioned ways.
An Xcode project has the ability to add subprojects. Ever since iOS 8, we have the ability to use Dynamic Frameworks. The great thing about Dynamic Frameworks is that they can contain resources like images as well as code. You can create a framework by creating a new project and choosing iOS > Framework & Library > cocoa touch framework.
Drag the framework’s xcode project into your project heirarchy to add the framework into your project; Then add the framework product into embedded binaries.
Now your dependency graph looks like this (ios_project → framework_A)
You should be able to run this on simulator and device. But what if we were to make a dependency graph that looks like this? (iOS_project → framework_A → framework_B)
Essentially a framework of a framework?
Well, for somereason your iOS_project NEEDS to embed framework_B. You’d think that embedding framework_A would automatically embed framework_B but unfortunately it does not.
If you run your app in simulator you will find that it will run. But if you run it on the device (i.e. iPhone) it will crash with an error “image not found” and that it can’t find the dynamic libary. Ok, the fix is to add framework_B into the embedded binary.
Yay it works!
but… share it with someone else or clean your project and it stops working. what happened?
framework_B by default has an absolute path to the derivedData. Derived data is a file with some nice junk that gets generated and has a unique name. So if you clean your project that file goes away and is replaced with a new one. Now your project tries looking for the old one and can not find it.
Not to worry. you can just change it to use a path “Relative to build products”
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.stackoverflow.com