1

Whats the role of NSCoder here?

- (id)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self)
    {

    }
    return self;
}
justin
  • 104,054
  • 14
  • 179
  • 226
suhail
  • 19
  • 4

2 Answers2

1

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.

justin
  • 104,054
  • 14
  • 179
  • 226
0

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

craigmj
  • 4,827
  • 2
  • 18
  • 22