Created
March 5, 2014 05:38
-
-
Save hachinobu/9361841 to your computer and use it in GitHub Desktop.
CoreDataよりNSFetchRequestをsetReturnsDistinctResults:YES、setResultType:NSDictionaryResultTypeで取得した際に返り値であるNSDictionaryをNSManagedObjectに変換する方法
This file contains hidden or 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)initWithDictionary:(NSDictionary *)dict managedContext:(NSManagedObjectContext *)context | |
{ | |
self = [super initWithEntity:[NSEntityDescription entityForName:[[self class] entityName] inManagedObjectContext:context] insertIntoManagedObjectContext:nil]; | |
if (self) { | |
for (NSString *key in dict.allKeys) { | |
[self setValue:dict[key] forKey:key]; | |
} | |
} | |
return self; | |
} | |
+ (NSString *)entityName | |
{ | |
return NSStringFromClass([self class]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment