Question

Is it possible to generate xcdatamodel file from json? Here's how i imagine it would work: Given a JSON file, going through some program with some custom logic (will probably be written by myself), will generate xcdatamodel file for me to use in XCode project. My question is: is it possible? has anyone ever done it?

Was it helpful?

Solution

I don't think it's possible to create an xcdatamodel file in code. The format isn't documented anywhere and includes layout properties that are only relevant in Xcode's GUI model builder. Those files are also converted to "compiled" .mom files during the build process.

However, you can create an NSManagedObjectModel entirely in code. See this listing for an example: Creating a managed object model in code (Core Data Programming Guide).

NSManagedObjectModel also implements NSCoding, so it should be possible to persist the model you generate to a file using NSKeyedArchiver.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top