ios - NSKeyedArchiver archivedDataWithRootObject return nil when passed an array of image model -


i trying save array containing models consist of image , string using [nskeyedarchiver archiveddatawithrootobject:dataarray]; method returns nil after 2-3 times of calling method . happens when model trying archive contains image. have checked data array not nil. beneath code using :

@implementation imagesmodel  - (id)initwithcoder:(nscoder *)coder{     if(self = [super init]){         self.image = [[uiimage alloc]initwithdata:[coder decodeobjectforkey:@"image"]];         self.urlstring = [coder decodeobjectforkey:@"urlstring"];     }     return self; }  - (void)encodewithcoder:(nscoder *)coder {     [coder encodeobject:uiimagepngrepresentation(self.image) forkey:@"image"];     [coder encodeobject:self.urlstring forkey:@"urlstring"]; }  + (nsdictionary *)getobjectmapper {     if (!mapperdictionary) {         nsmutabledictionary *dictionary = [nsmutabledictionary dictionary];         [dictionary setobject:[propertymapping mappingforsimpletypewithmappedkeyname:@"image"] forkey:@"image"];         [dictionary setobject:[propertymapping mappingforsimpletypewithmappedkeyname:@"urlstring"] forkey:@"urlstring"];         mapperdictionary = [dictionary copy];     }     return mapperdictionary; } - (nsdata)archivedata {     if (!dataarray){        return no;  //nothing save      }  nsdata *data = [nskeyedarchiver archiveddatawithrootobject:dataarray]; //return nil  } 

it depends on how have loaded image. here answer might you:

how encode uiimage in `nscoder`

also, might want use uiimagejpegrepresentation if want store .jpeg images.


Comments