Skip to content

Instantly share code, notes, and snippets.

@objectiveSee
Last active December 11, 2015 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save objectiveSee/4599970 to your computer and use it in GitHub Desktop.
Save objectiveSee/4599970 to your computer and use it in GitHub Desktop.
/////// .h ///////
// Core Data MOM file: http://grab.by/jf4c
// NOTE: Some attributes excluded in the code below
@interface CDUserPhotos : NSManagedObject
@property (nonatomic, retain) NSData * data; // core data attribute
@property (nonatomic, readonly) NSArray* albums; // not an attribute. Calculate from self.data
@end
/////// .m ///////
@dynamic data;
@synthesize albums;
#pragma mark -
#pragma mark NSManagedObject
- (void)awakeFromFetch
{
[super awakeFromFetch]; // must be called first
[self _updateTransient];
}
- (void)didSave
{
[super didSave];
[self _updateTransient];
}
- (void)didTurnIntoFault
{
[super didTurnIntoFault];
self.albums = nil;
}
- (void)_updateTransient
{
if ( self.data != nil )
{
self.albums = [self.data objectFromJSONData];
}
else
{
self.albums = nil;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment