Please take a look at these two simple pieces of code. This
- (void)testMethod
{
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"myEncodedObjectKey"];
self = (Profile *) [NSKeyedUnarchiver unarchiveObjectWithData:data];
for (int i = 0; i < self.avatar.count; i++)
[self.avatar replaceObjectAtIndex:i withObject:[UIImage imageWithData:[self.avatar objectAtIndex:i]]];
if ([[self.avatar objectAtIndex:0] isKindOfClass:[UIImage class]])
NSLog(@"UIImage");//at this moment it's UIImage
}
and this:
[currentProfile testMethod];
if ([[currentProfile.avatar objectAtIndex:0] isKindOfClass:[NSData class]])
NSLog(@"NSData");//Moment later it is NSData
In the first one i fetch a custom object from the NSUserDefaults and work with a NSMutableArray variable named "avatar". I convert its each object from NSData to UIImage. Then i check what i've got by using NSLog . It's UIImage. At the second piece of code you can see how a moment later what was UIImage turns back to NSData by its own will. Seems like i described my issue clearly. Do you understand what's going on? I don't. Thanks a lot in advance for your attention