Given the following definition of a class with retain properties:
@interface FeedEntry : NSObject<NSCoding>
{
NSURL* url;
NSData* source;
}
@property (retain) NSURL* url;
@property (retain) NSData* source;
@end
@implementation FeedEntry
@synthesize url;
@synthesize source;
-(void)encodeWithCoder:(NSCoder*)coder
{
[coder encodeObject:url forKey:@"url"];
[coder encodeObject:source forKey:@"source"];
}
Why does the url property in initWithCoder method need the "retain":
-(id)initWithCoder:(NSCoder*)coder
{
url = [[coder decodeObjectForKey:@"url"] retain];
source = [coder decodeObjectForKey:@"source"];
NSLog(@"got url=%@\n", url);
return self;
}
Specifically, why doesn't the synthesized "get url" method retain the object? (I'm guessing the source property will need a retain as well).