sweepy_ sweepy_ - 5 months ago 41x
Swift Question

Embed external framework into home-made private framework in Swift

I built a framework using Xcode 6 and Swift, and my framework uses SwiftyJSON as a dependency - added through Carthage. I archived my framework and created a build for both simulator and iOS devices using

, and when trying to use my framework into an empty app, I get a crash at runtime:

dyld: Library not loaded: @rpath/SwiftyJSON.framework/SwiftyJSON
Referenced from: /Users/hd/Library/Developer/CoreSimulator/Devices/324FD1CD-4A06-459B-AE6D-318197B5697E/data/Containers/Bundle/Application/555871BB-7AA1-4AED-90CE-EE0A628A794F/CollaborativeTodo.app/Frameworks/XXXXX.framework/XXXXX
Reason: no suitable image found. Did find:
/Users/hd/Library/Developer/CoreSimulator/Devices/324FD1CD-4A06-459B-AE6D-318197B5697E/data/Containers/Bundle/Application/555871BB-7AA1-4AED-90CE-EE0A628A794F/CollaborativeTodo.app/Frameworks/SwiftyJSON.framework/SwiftyJSON: no matching architecture in universal wrapper

Here's what my arborescence look like -- my framework name is deliberately blurred:

Project arborescence

General tab:


Build Phases:
Build Phases

It works if I include SwiftyJSON using Carthage in my project, but I don't want the user to be forced to include third-party libraries. How to embed SwiftyJSON into my framework and tell Xcode to use the embedded version at runtime, instead of trying to find the framework in the project?


You can't avoid having the app include SwiftlyJSON directly. Better said, you should not avoid having the app include SwiftlyJSON. If the app already has SwiftlyJSON for some other reason, you will cause them a huge amount of pain due to duplicated symbols. Depending on exactly how they do things, they may not get errors, just undefined behavior, which is worse. Auto-inclusion is the kind of feature that is very nice until it completely explodes and no one can figure out how to fix it. If you search "ios duplicated symbols" here on StackOverflow, I estimate about half of them are due to a framework trying to auto-include a sub-framework (often SBJSON).

Document what you rely on and include it in your Cartfile as a nested dependency. Carthage will build it for them (they'll still need to drag it into their project).