Reputation: 750
I have spent a few days learning and writing NSCoding and finally got it working. However, it took very long to archive and unarchive the (quite complex) object graph, which is unacceptable. After searching the internet for some time, I think the better way is to use core data.
Do you recommend that 1) I should rewrite all my classes as subclasses of NSManagedObject or 2) should I create an instance variable of NSManagedObject in each of my class so that any changes to the class also updates its core data representation? Doing either way will need significant changes to the exiting classes and I think I have to update lots of unit test cases as well if it changes the way the classes are initialized.
What do you recommend? I really don't want to head to the wrong approach again...
Thanks!
Upvotes: 1
Views: 598
Reputation: 34185
I would recommend 1), if you use Core Data.
2) doesn't make much sense. For example, say A* a1
and A* a2
refer to the same B* b
. If A
and B
are subclasses of NSManagedObject
, this relationship can be easily saved to and then be retrieved from the file. But if A
and B
have NSManagedObject
instances as ivars, how do you maintain this relationship that two A
s refer to one B
? You will be forced to write a whole lot of glue codes, which are basically provided by the Core Data APIs.
If you decide to use Core Data, one very important advice I can give is to read Apple's documentations very, very carefully from the start to the finish, and to resist the urge to write codes from the day one. Core Data is a rather big set of API, and a good grasp of the whole structure before starting to write codes will save you many days afterwards.
Upvotes: 2