Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixes the import method never returning a valid array of imported objects #539

Merged
merged 1 commit into from

1 participant

@tonyarnold
Owner

Importing data does not save immediately, and acts directly upon the information that is passed. Fixes an error where the imported array of objects was always returned as nil.

This pull request is based upon work done by @badeen in #535.

@tonyarnold tonyarnold Importing data does not save immediately, and acts directly upon the …
…information that is passed. Fixes an error where the imported array of objects was always returned as nil.
a2c807c
@tonyarnold tonyarnold was assigned
@tonyarnold tonyarnold merged commit a2ddb92 into magicalpanda:develop
@tonyarnold tonyarnold deleted the tonyarnold:feature/fix-async-data-import-early-return branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 19, 2013
  1. @tonyarnold

    Importing data does not save immediately, and acts directly upon the …

    tonyarnold authored
    …information that is passed. Fixes an error where the imported array of objects was always returned as nil.
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.