ios - Storing complete class object into database in iPhone -


i new development.

i want store complete object of class database. creating application user can add multiple views parent view , want save it, next time when user fetches it, ever has saved i.e. views parent view previously.

any logic or suggestion on same helpful,

thanks in advance

any object want save need conform nscoder protocol. keep in mind if have custom objects within parent object need conform nscoder. add following methods custom class(es).

- (id)initwithcoder:(nscoder *)coder {   _inventory = [[coder decodeobjectforkey:@"inventory"] retain];    return self; }  - (void)encodewithcoder:(nscoder *) encoder{   [encoder encodeobject:_inventory forkey:@"inventory"]; }  

in example above want encode player's inventory. if inventory contains custom objects (as opposed bunch of nsstrings example) they'll need own nscoder methods.

below turn can save out nsuserdefaults. adjust appropriately store in db. keep in mind if want send nsdata on wire store in db you'll want convert base64 , possibly compress it.

nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; nsdata * encodedobject = [nskeyedarchiver archiveddatawithrootobject:rootobject];  [defaults setobject:encodedobject forkey:ksavearchivekey]; [defaults synchronize]; 

to go other way, you'll want grab nsdata, whatever magic on described above (base64, compression) , unarchive.

playerinventory *inventory = [nskeyedunarchiver unarchiveobjectwithdata:playerinventorydata] 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -