-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathNSManagedObjectContext+Additions.m
More file actions
44 lines (33 loc) · 1.19 KB
/
NSManagedObjectContext+Additions.m
File metadata and controls
44 lines (33 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// NSManagedObjectContext+Additions.m
// Shopify_Mobile
//
// Created by Matthew Newberry on 7/12/10.
// Copyright 2010 Shopify. All rights reserved.
//
#import "NSManagedObjectContext+Additions.h"
@implementation NSManagedObjectContext (NSManagedObjectContext_Additions)
- (BOOL) save{
int insertedObjectsCount = [[self insertedObjects] count];
int updatedObjectsCount = [[self updatedObjects] count];
int deletedObjectsCount = [[self deletedObjects] count];
NSDate *startTime = [NSDate date];
NSError *error;
if(![self save:&error]) {
NSLog(@"Failed to save to data store: %@", [error localizedDescription]);
NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
if(detailedErrors != nil && [detailedErrors count] > 0) {
for(NSError* detailedError in detailedErrors) {
NSLog(@" DetailedError: %@", [detailedError userInfo]);
}
}
else {
NSLog(@" Error:%@", [error userInfo]);
}
return NO;
}
if([ActiveManager shared].logLevel > 0)
NSLog(@"Created: %i, Updated: %i, Deleted: %i, Time: %f seconds", insertedObjectsCount, updatedObjectsCount, deletedObjectsCount, ([startTime timeIntervalSinceNow] *-1));
return YES;
}
@end