In the source code I found in a book there's an implementation of -initWithCoder: that basically looks like this:
But, this looks potentially problematic. Isn't something like this better and safer?
If super's init creates some internal variables directly, without accessing them through properties, then things allocated in first -init call would leak.
Code:
- (id)initWithCoder:(NSCoder *)decoder
{
if (self = [super init]) {
NSData *data = [decoder decodeObjectForKey:kImageKey];
self = [self initWithData:data];
}
return (self);
}
But, this looks potentially problematic. Isn't something like this better and safer?
Code:
- (id)initWithCoder:(NSCoder *)decoder
{
NSData *data = [decoder decodeObjectForKey:kImageKey];
self = [self initWithData:data];
return (self);
}
If super's init creates some internal variables directly, without accessing them through properties, then things allocated in first -init call would leak.