Last active
December 11, 2015 12:18
-
-
Save objectiveSee/4599970 to your computer and use it in GitHub Desktop.
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
/////// .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