I have seen different question on stackoverflow related to this topic. Some says that NSCoding
does not conform with UIImage
and other says that with iOS 5, it does conform.
I want to persist images in my app. I am using encode
and decode
methods and everything (title, labels etc) are persisting but NOT the images.
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:title forKey:@"title"];
[aCoder encodeObject:link forKey:@"link"];
[aCoder encodeObject:creator forKey:@"creator"];
[aCoder encodeObject:pubDate forKey:@"pubDate"];
// [aCoder encodeObject:thumbnail forKey:@"thumbnail"];
[aCoder encodeObject:UIImagePNGRepresentation(thumbnail) forKey:@"thumbnail"];
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self)
{
[self setTitle:[aDecoder decodeObjectForKey:@"title"]];
[self setLink:[aDecoder decodeObjectForKey:@"link"]];
[self setCreator:[aDecoder decodeObjectForKey:@"creator"]];
[self setPubDate:[aDecoder decodeObjectForKey:@"pubDate"]];
[self setThumbnail:[aDecoder decodeObjectForKey:@"thumbnail"]];
}
return self;
}
I am also using UIPNGRepresentation
but its not working. Can someone help me with this.
Thanks.