When am I supposed to use the initWithCoder: method?
Yes, if you are using a custom class in IB, then those objects are instantiated with the initWithCode:
method. So, in your class you would override:
-(id) initWithCoder:(NSCoder*)aDecoder {
if (! (self = [super initWithCoder:aDecoder]))
return nil;
// object has been created from IB... do initialization stuff here
return self;
}
You are supposed to use the initWithCoder:
method when you are working with objects that have been archived. For example when you specifically use NSKeyedUnarchiver
to create these archived objects or when you need to add custom initialization code to objects that are coming from a xib file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With