objective c - Storing Custom Object in NSMutableDictionary -
i trying store custom object in nsmutabledictionary. after saving when read object nsmutabledictionary it's null.
here code
//saving
nsmutabledictionary *dict = [[nsmutabledictionary alloc] init]; customobject *obj1 = [[customobject alloc] init]; obj1.property1 = @"my first property"; [dict setobject:obj1 forkey:@"firstobjectkey"]; [dict writetofile:[self datafilepath] atomically:yes]; // reading
nsstring *filepath = [self datafilepath]; nsmutabledictionary *dict = [[nsmutabledictionary alloc] initwithcontentsoffile:filepath]; customobject *tempobj = [dict objectforkey:@"firstobjectkey"]; nslog(@"object %@", tempobj); nslog(@"property1:%@,,tempobj.property1); how can store custom class object in nsmutabledictionary?
writetofile method can store standard types of objects plist. if have custom object you'd have use nskeyedarchiver/nskeyedunarchiver this.
Comments
Post a Comment