Reputation: 9700
I’m going to port my iOS app to OS X (and perhaps tvOS after that). It uses the wonderful Realm for persistence. I’m currently in the process of breaking out the data model in my application into a dynamic framework, which I intend to use in both the iOS and OS X targets, to share that code, since it’s completely independent of UI.
I’m wondering what the best way to get Realm included here is. I will no longer need / want it as a dependency on the app itself, but I’d like the app to depend on the dynamic framework, then for that framework to depend on Realm. I don’t mind how this is done, i.e. I’m not particularly tied to Cocoapods.
The idea is that the apps themselves don’t see or care about Realm, or the persistence model used inside the framework. Like so:
iOS App -> Dynamic Framework -> RealmSwift
OS X App -> Dynamic Framework -> RealmSwift
tvOS App -> Dynamic Framework -> RealmSwift
-> = Depends on
I’d also like, if possible, for this to be smart, and include either the iOS or OS X builds of Realm, so that all I need to do is build the respective target in my Xcode project, and it’ll grab the right framework, right version of Realm, and all will be well.
How might I go about this? Is Cocoapods going to allow this? Is the dynamic framework the right idea in the first place? Should I make a podspec for the dynamic framework?
Upvotes: 2
Views: 809
Reputation: 4285
You can create middleware by defining s.dependency "Realm"
in the podspec for your dynamic framework, if you think of it as just another pod in your app then you can have a nice abstraction layer that keeps you working above Realm specifically, I do this with analytics via ARAnalytics.
In terms of real-world linking, you'll have to link Realm to your app though, the runtime doesn't easily allow scoping a dependency specific to another library, as they exist inside a flat object graph.
Upvotes: 2