I tried to save NSMutableArray which contains five UIImages to NSUserDefaults and didn’t work. i got warning
-[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '(
"UIImage: 0x4c76570,
"UIImage: 0x4c76570",
"UIImage: 0x4c76570",
"UIImage: 0x4c76570",
"UIImage: 0x4c76570"
)' of class '__NSArrayM'.
OK seems like i need to archive my Array into NSData. But how do i make UIImage to conform NSCoding? Should i transform my images to NSData first or maybe there is an easier way?
Yes, you’ll need to either use the
UIImagePNGRepresentationorUIImageJPEGRepresentationfunctions to retrieve the image’s binary data in the desired format, which you can then serialize into anNSArray.An example: