Last active
December 17, 2015 17:09
-
-
Save noahmiller/5644319 to your computer and use it in GitHub Desktop.
Example usage of https://gist.github.com/anonymous/5644255
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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