Skip to content
Browse files

Merge pull request #539 from tonyarnold/feature/fix-async-data-import…

…-early-return

Fixes the import method not returning a valid array of imported objects
  • Loading branch information...
2 parents 73670a2 + a2c807c commit a2ddb92f867fa49564ec53dcfd2f4cc37f072abc @tonyarnold committed Aug 19, 2013
Showing with 9 additions and 15 deletions.
  1. +9 −15 MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalDataImport.m
View
24 MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalDataImport.m
@@ -271,24 +271,18 @@ + (NSArray *) MR_importFromArray:(NSArray *)listOfObjectData
+ (NSArray *) MR_importFromArray:(NSArray *)listOfObjectData inContext:(NSManagedObjectContext *)context
{
- NSMutableArray *objectIDs = [NSMutableArray array];
-
- [MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext)
- {
- [listOfObjectData enumerateObjectsWithOptions:0 usingBlock:^(id obj, NSUInteger idx, BOOL *stop)
- {
- NSDictionary *objectData = (NSDictionary *)obj;
+ NSMutableArray *dataObjects = [NSMutableArray array];
- NSManagedObject *dataObject = [self MR_importFromObject:objectData inContext:localContext];
+ [listOfObjectData enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
+ {
+ NSDictionary *objectData = (NSDictionary *)obj;
- if ([context obtainPermanentIDsForObjects:[NSArray arrayWithObject:dataObject] error:nil])
- {
- [objectIDs addObject:[dataObject objectID]];
- }
- }];
+ NSManagedObject *dataObject = [self MR_importFromObject:objectData inContext:context];
+
+ [dataObjects addObject:dataObject];
}];
-
- return [self MR_findAllWithPredicate:[NSPredicate predicateWithFormat:@"self IN %@", objectIDs] inContext:context];
+
+ return dataObjects;
}
@end

0 comments on commit a2ddb92

Please sign in to comment.
Something went wrong with that request. Please try again.