rustylepord rustylepord - 1 year ago 69
iOS Question

Maintain multiple instances of the Relam

I am developing a SDK , a static library which will be sold to third parties. This static library will be using Relam as the data store.

I am planning for a scenario where my client also has a data store using Relam on his app. I do not want them to change / migrate their data store because they are incorporating my SDK.

Can we have multiple data stores / instances when using Relam ?

Or Is there any other better way to handle this situation ?

Answer Source

I'll answer this in two parts:

Part 1 - Code Architecture

If you're internally using Realm in a library, and you're worried that your use of Realm might bleed into a user's code if they're also using Realm, there are ways to mitigate this.

You're correct in that using RLMRealmConfiguration will let you properly separate the majority of your Realm implementation from theirs. You can use the fileURL to explicitly dictate where your Realm file will be saved, and the objectClasses to explicitly define that only your own RLMObject classes will be saved to it.

This may need testing, but the opposite is also true. Realm uses Objective-C reflection to add all RLMObject classes by default. As such, unless the user also specifies objectClasses in their configuration, the schema for your library's model objects may appear in their Realm files. This would be harmless, but it may look strange to the user.

Part 2 - Distribution

It's not great to have 2 copies of the same framework in one static binary. Especially when it's conceivable that the user could start using a newer version of Realm than what's in your library. As such, I'd definitely recommend keeping Realm as a dynamic framework dependency for your library; so both your library and the user's code can target the same codebase.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download