Skip to content

Instantly share code, notes, and snippets.

@hachinobu
Created March 5, 2014 05:38
Show Gist options
  • Save hachinobu/9361841 to your computer and use it in GitHub Desktop.
Save hachinobu/9361841 to your computer and use it in GitHub Desktop.
CoreDataよりNSFetchRequestをsetReturnsDistinctResults:YES、setResultType:NSDictionaryResultTypeで取得した際に返り値であるNSDictionaryをNSManagedObjectに変換する方法
- (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