Reputation: 8503
I am planning on creating my app in a 'Model-View-Controller
'(MVC)-style, and in the end, for me at least, this means that all data is stored in the controller-class. Let's say I have a class Player
, and the player has several objects of class Weapons
or Equipment
or whatever. The initialization of Controller*
stores the player(s), so if I can store/save only the Controller
-object over time, even if the app or the device restarts, that would be nice. I did this in Java one, I put in Serialization = 100L;
(or something like it) in the top of the file of every object that would be included when saving the Controller
-object, and it worked perfectly. Is this possible in ios/cocoa-touch/objective-c?
I have read and used Core Data
(not very much), but that is just a database-table, sql?, which would have me extract every piece of information of every object?
For instance, if the object Player*
has a member NSString *name;
, I would have to save the actual string in Core Data, instead of saving the object of the player? Like, varchar.
If there is any way to store an entire custom object on the device for further use, I would very much like to know what it's called, and where I can read about it/tutorials.
Upvotes: 0
Views: 162
Reputation: 41652
Read up on the NSCoding protocol. You can make your object complient to it, then serialized it and save it to a file. Later you can restore it to the same state by using a decoder. For sure some other posts that cover this topic on SO.
Upvotes: 1