-
-
Save fra3il/6d2af5051bc556bac8ab to your computer and use it in GitHub Desktop.
[WP/160] How to store custom class using CoreData
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
@interface DBMetadata : NSObject <NSCoding> { | |
BOOL thumbnailExists; | |
long long totalBytes; | |
NSDate *lastModifiedDate; | |
NSString *path; | |
// ... | |
} |
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
- (id)initWithCoder:(NSCoder *)coder { | |
if ((self = [super init])) { | |
thumbnailExists = [coder decodeBoolForKey:@"thumbnailExists"]; | |
totalBytes = [coder decodeInt64ForKey:@"totalBytes"]; | |
lastModifiedDate = [coder decodeObjectForKey:@"lastModifiedDate"]; | |
path = [[coder decodeObjectForKey:@"path"] retain]; | |
// ... | |
} | |
return self; | |
} | |
- (void)encodeWithCoder:(NSCoder *)coder { | |
[coder encodeBool:thumbnailExists forKey:@"thumbnailExists"]; | |
[coder encodeInt64:totalBytes forKey:@"totalBytes"]; | |
[coder encodeObject:lastModifiedDate forKey:@"lastModifiedDate"]; | |
[coder encodeObject:path forKey:@"path"]; | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment