Skip to content

Instantly share code, notes, and snippets.

@OneSadCookie
Created November 29, 2011 23:36
Show Gist options
  • Save OneSadCookie/1407168 to your computer and use it in GitHub Desktop.
Save OneSadCookie/1407168 to your computer and use it in GitHub Desktop.
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[super encodeWithCoder:aCoder];
[aCoder encodeObject:_vValue forKey:@"vValue"];
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (!self) return nil;
_vValue = [[aDecoder decodeObjectForKey:@"vValue"] retain]; // don't retain in ARC
if (/* !vValue || */ ![vValue isKindOfClass:[Whatever class]])
{
[self dealloc]; // not in ARC
return nil;
}
return self;
}
@mysteriouspants
Copy link

Also helpful is my thoughtfully compiled NSCoding Tips, though it looks like you're trying to show conditional encoding (which is slightly more fun to do).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment