I am storing some Objective C based objects in to NSuserdefaults.
To retrieve data from NSuserDefaults, I use initWithCoder method.
I have seen two different implementations of this:
Implementation 1
- (id)initWithCoder:(NSCoder *)decoder {
self = [super init];
if (self != nil){
//decode properties, other class vars
self.variable = [decoder decodeObjectForKey:@"variable"];
}
return self;
}
Implementation 2
- (id)initWithCoder:(NSCoder *)decoder {
self = [[CustomClass alloc] init];
if (self != nil){
//decode properties, other class vars
self.variable = [decoder decodeObjectForKey:@"variable"];
}
return self;
}
Which is the correct way?
What is the difference between these two?