iphone - Storing custom OrderedDictionary to NSUserDefaults -


i need save ordereddictionary nsuserdefaults.

i read here , in many other posts how it:

-(id)initwithcoder:(nscoder *)decoder{      if (self != nil){          dictionary = [decoder decodeobjectforkey:@"dictionary"];          array = [decoder decodeobjectforkey:@"array"];      }     return self; }  -(void)encodewithcoder:(nscoder *)encoder{     [encoder encodeobject: dictionary forkey:@"dictionary"];     [encoder encodeobject: array forkey:@"array"]; } 

i call this:

 ordereddictionary *od = [ordereddictionary dictionarywithdictionary:[businessinfo objectforkey:@"allowedstates"]];     nsdata *archivedobject = [nskeyedarchiver archiveddatawithrootobject:od];     nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults];     [defaults setobject:archivedobject forkey:@"allowedstates"];     [defaults synchronize]; 

and unarchive this:

nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults];     nsdata *archivedobject = [defaults objectforkey:@"allowedstates"];     ordereddictionary *countrystates = (ordereddictionary *)[nskeyedunarchiver unarchiveobjectwithdata:archivedobject]; 

i see archivedobject not empty, countrystates empty, although when save it's not empty.

how it?

how can archive ordereddictionary?

edited

the method initwithcoder being called, not encodewithcoder

please refer below link, may proper solution.

encodewithcoder not called in derived class of nsmutabledictionary

when encodewithcoder called?

good luck !!!!


Comments