Skip to content

Instantly share code, notes, and snippets.

@fra3il

fra3il/0.h Secret

Last active February 2, 2016 01:30
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 fra3il/6d2af5051bc556bac8ab to your computer and use it in GitHub Desktop.
Save fra3il/6d2af5051bc556bac8ab to your computer and use it in GitHub Desktop.
[WP/160] How to store custom class using CoreData
@interface DBMetadata : NSObject <NSCoding> {
BOOL thumbnailExists;
long long totalBytes;
NSDate *lastModifiedDate;
NSString *path;
// ...
}
- (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