Reputation: 19
Whats the role of NSCoder here?
- (id)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self)
{
}
return self;
}
Upvotes: 1
Views: 1766
Reputation: 104698
NSCoder
holds the state you saved the archive representation of the instance to initialize in -[id<NSCoding> encodeWithCoder:]
.
In other words, you encoded an instance of self at one point in time, now you need the coder's info to restore your state.
Upvotes: 1
Reputation: 5077
NSCoder handles archiving, most particularly in this typical case of a view, the archiving of a NIB. So when you initWithCoder
the NIB is loaded, with the interface you've constructed in Interface Builder.
You can read more here: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Protocols/NSNibAwaking_Protocol/Reference/Reference.html
Upvotes: 0