Skip to content

Instantly share code, notes, and snippets.

@saikat
Created September 15, 2009 07:41
Show Gist options
  • Save saikat/187172 to your computer and use it in GitHub Desktop.
Save saikat/187172 to your computer and use it in GitHub Desktop.
var WidgetJSON = @"WidgetJSON";
@implementation Screen (CPCoding)
- (id)initWithCoder:(CPCoder)aCoder
{
// This code will only work when this screen is in the main window - that should
// always be the case
var jsonObject = [aCoder decodeObjectForKey:WidgetJSON];
return [[CPClassFromString(jsonObject.widgetType) alloc] initFromJSON:jsonObject];
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
[aCoder encodeObject:[[self toJSON] objectFromJSON] forKey:WidgetJSON];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment