Skip to content

Instantly share code, notes, and snippets.

@noahmiller
Last active December 17, 2015 17:09
Show Gist options
  • Save noahmiller/5644319 to your computer and use it in GitHub Desktop.
Save noahmiller/5644319 to your computer and use it in GitHub Desktop.
#pragma mark - State preservation
- (void)encodeRestorableStateWithCoder:(NSCoder*)coder
{
[super encodeRestorableStateWithCoder:coder];
// Preserve the managed objects
NSData* data =
[AManagedObjectArchiver ArchiveDataFromBlock:^(AManagedObjectArchiver* archiver)
{
[archiver encodeObject:self.rabbits forKey:@"rabbits"];
}];
[coder encodeObject:data forKey:@"rabbits"];
}
- (void)decodeRestorableStateWithCoder:(NSCoder*)coder
{
[super decodeRestorableStateWithCoder:coder];
// Restore the rabbits
NSMutableData* data = [coder decodeObjectForKey:@"rabbits"];
[AManagedObjectUnarchiver UnarchiveData:data
Context:[NSManagedObjectContext MR_defaultContext]
Block:^(AManagedObjectUnarchiver* unarchiver)
{
self.rabbits = [unarchiver decodeObjectForKey:@"rabbits"];
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment