Reputation: 161
Is it possible to create a Realm schema programatically without pre-defining it in a file? In other words, am I able to create object schemas dynamically during run time?
Thank you for your help.
Upvotes: 4
Views: 1333
Reputation: 15991
Yes, it's technically possible at the Objective-C runtime level to dynamically generate Realm object subclasses with properties determined at runtime, and to subsequently add them as a new model object to a Realm file.
That being said, it's not an officially supported way of using Realm, and would require a fair amount of boilerplate code. If you can, I would recommend re-thinking your architecture to see if it's possible to achieve what you're aiming to do another way.
Sandy Chapman is right in that this question may be a little too broad for Stack Overflow and it might be better off as a new issue on the Realm-Cocoa GitHub repo.
Upvotes: 3