Skip to content

Commit

Permalink
Fix some error handling warnings from the analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
Collin Ruffenach committed Nov 10, 2014
1 parent f61b719 commit 8534ab0
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions CRLoom/NSManagedObject+CRLoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,23 @@ + (NSManagedObject*)importObject:(NSDictionary*)data
return (CRShouldSaveContext(moc) && saveOnCompletion) ? [moc save:error] ? object : nil : object;
}

+ (void)prepareForImportOfData:(NSArray*)data
+ (BOOL)prepareForImportOfData:(NSArray*)data
intoContext:(NSManagedObjectContext*)moc
error:(NSError* __autoreleasing *)error {
NSArray *idsToImport = [data valueForKeyPath:[@"@distinctUnionOfObjects." stringByAppendingString:[self uniqueDataIdentifierKey]]];
NSArray *existingObjects = [[moc executeFetchRequest:[self emptyFetchRequest] error:error] mutableCopy];

if (error && *error != nil) {
return NO;
}

[[existingObjects filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
return ![idsToImport containsObject:[evaluatedObject valueForKey:[self uniqueModelIdentifierKey]]];
}]] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[moc deleteObject:obj];
}];

return YES;
}

+ (NSArray*)importDataCollection:(NSArray*)data
Expand All @@ -256,9 +263,11 @@ + (NSArray*)importDataCollection:(NSArray*)data
error:(NSError* __autoreleasing *)error {

if (pruneExistingObjects) {
[self prepareForImportOfData:data
intoContext:moc
error:error];
if (![self prepareForImportOfData:data
intoContext:moc
error:error]) {
return nil;
}
}

NSDictionary *objects = guaranteedInsert ?
Expand Down Expand Up @@ -343,9 +352,11 @@ + (instancetype)existingObjectWithIdentifierValue:(id)value
withCache:(NSCache*)cache
error:(NSError* __autoreleasing *)error {
if (!value) {
*error = [NSError errorWithDomain:@"com.CRLoom.query"
code:0
userInfo:@{@"description" : @"Called existingObjectWithIdentifierValue:inContext:withCache:error: with a nil value."}];
if (error) {
*error = [NSError errorWithDomain:@"com.CRLoom.query"
code:0
userInfo:@{@"description" : @"Called existingObjectWithIdentifierValue:inContext:withCache:error: with a nil value."}];
}
return nil;
}
return [self findObjectWithData:@{[self uniqueDataIdentifierKey] : value}
Expand Down

0 comments on commit 8534ab0

Please sign in to comment.