开发者

Can Core Data be used for objects with variable schemas?

开发者 https://www.devze.com 2022-12-22 01:00 出处:网络
I\'m im开发者_StackOverflowplementing a new iPhone app and am relatively new to Cocoa development overall.I am at the stage of choosing how the persistence layer of this app will work, and it looks li

I'm im开发者_StackOverflowplementing a new iPhone app and am relatively new to Cocoa development overall. I am at the stage of choosing how the persistence layer of this app will work, and it looks like I'm basically choosing between Core Data and sqlite3.

The persisted models in this app are intended to have a schema that is loaded at runtime (from some kind of defn file, probably XML). By which I mean, this app is intended to have objects that are user-definable to some extent, e.g. the Customer type (which has certain built-in fields like "name" and "email") can be modified to have extra fields based on the user's specific needs (e.g. a user might want to add a "favourite fruit" field to their Customer type).

Having said that, will Core Data work for an app with a non-baked-in data model like this? I've just started playing around with the Core Data object designer thing in XCode and it seems like this thing wants to work with objects that have fixed fields that are compiled in.

I'm definitely trying to take the path of least resistance here, and I can see the benefits of using an Apple-supplied data framework, but don't want to start down that path if it's going to lock me into a data model that's defined at compile time.


The Core Data data model needs to be defined at compile time, but that does not mean you can't allow for custom fields to be added and used by end users.

It just means that you would define an entity for custom fields and create the fields as objects.

It is best to design a data model that meets your needs rather than think of how you would solve the problem in SQL.

0

精彩评论

暂无评论...
验证码 换一张
取 消