From 3d83091988cf866161fbca559eff32f45cbdd5df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvis=20Nu=C3=B1ez?= Date: Tue, 17 Feb 2015 19:13:30 +0100 Subject: [PATCH 1/2] Persist when processing finishes --- Source/Kipu.h | 7 ------- Source/Kipu.m | 22 ++++++++++++++++------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Source/Kipu.h b/Source/Kipu.h index 8e820897..fe3e4673 100644 --- a/Source/Kipu.h +++ b/Source/Kipu.h @@ -21,11 +21,4 @@ dataStack:(DATAStack *)dataStack completion:(void (^)(NSError *error))completion; -+ (void)processChanges:(NSArray *)changes - usingEntityName:(NSString *)entityName - predicate:(NSPredicate *)predicate - parent:(NSManagedObject *)parent - inContext:(NSManagedObjectContext *)context - completion:(void (^)(NSError *error))completion; - @end diff --git a/Source/Kipu.m b/Source/Kipu.m index 7d92fdc7..6f52e1ff 100644 --- a/Source/Kipu.m +++ b/Source/Kipu.m @@ -12,11 +12,13 @@ - (NSManagedObject *)kipu_copyInContext:(NSManagedObjectContext *)context; - (NSArray *)kipu_relationships; - (void)kipu_processRelationshipsUsingDictionary:(NSDictionary *)objectDict - andParent:(NSManagedObject *)parent; + andParent:(NSManagedObject *)parent + dataStack:(DATAStack *)dataStack; - (void)kipu_processToManyRelationship:(NSRelationshipDescription *)relationship usingDictionary:(NSDictionary *)objectDict - andParent:(NSManagedObject *)parent; + andParent:(NSManagedObject *)parent + dataStack:(DATAStack *)dataStack; - (void)kipu_processToOneRelationship:(NSRelationshipDescription *)relationship usingDictionary:(NSDictionary *)objectDict; @@ -50,6 +52,7 @@ + (void)processChanges:(NSArray *)changes predicate:predicate parent:nil inContext:backgroundContext + dataStack:dataStack completion:completion]; }]; } @@ -70,6 +73,7 @@ + (void)processChanges:(NSArray *)changes predicate:predicate parent:safeParent inContext:backgroundContext + dataStack:dataStack completion:completion]; }]; } @@ -79,6 +83,7 @@ + (void)processChanges:(NSArray *)changes predicate:(NSPredicate *)predicate parent:(NSManagedObject *)parent inContext:(NSManagedObjectContext *)context + dataStack:(DATAStack *)dataStack completion:(void (^)(NSError *error))completion { [NSManagedObject andy_mapChanges:changes @@ -90,12 +95,12 @@ + (void)processChanges:(NSArray *)changes NSManagedObject *created = [NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:context]; [created hyp_fillWithDictionary:objectDict]; - [created kipu_processRelationshipsUsingDictionary:objectDict andParent:parent]; + [created kipu_processRelationshipsUsingDictionary:objectDict andParent:parent dataStack:dataStack]; } updated:^(NSDictionary *objectDict, NSManagedObject *object) { [object hyp_fillWithDictionary:objectDict]; - [object kipu_processRelationshipsUsingDictionary:objectDict andParent:parent]; + [object kipu_processRelationshipsUsingDictionary:objectDict andParent:parent dataStack:dataStack]; }]; @@ -103,7 +108,9 @@ + (void)processChanges:(NSArray *)changes [context save:&error]; if (error) NSLog(@"Kipu (error while saving %@): %@", entityName, [error description]); - if (completion) completion(error); + [dataStack persistWithCompletion:^{ + if (completion) completion(error); + }]; } + (NSManagedObject *)safeObjectInContext:(NSManagedObjectContext *)context @@ -148,12 +155,13 @@ - (NSArray *)kipu_relationships - (void)kipu_processRelationshipsUsingDictionary:(NSDictionary *)objectDict andParent:(NSManagedObject *)parent + dataStack:(DATAStack *)dataStack { NSArray *relationships = [self kipu_relationships]; for (NSRelationshipDescription *relationship in relationships) { if (relationship.isToMany) { - [self kipu_processToManyRelationship:relationship usingDictionary:objectDict andParent:parent]; + [self kipu_processToManyRelationship:relationship usingDictionary:objectDict andParent:parent dataStack:dataStack]; } else { if (parent) { [self setValue:parent forKey:relationship.name]; @@ -167,6 +175,7 @@ - (void)kipu_processRelationshipsUsingDictionary:(NSDictionary *)objectDict - (void)kipu_processToManyRelationship:(NSRelationshipDescription *)relationship usingDictionary:(NSDictionary *)objectDict andParent:(NSManagedObject *)parent + dataStack:(DATAStack *)dataStack { NSString *childEntityName = relationship.destinationEntity.name; NSString *parentEntityName = parent.entity.name; @@ -207,6 +216,7 @@ - (void)kipu_processToManyRelationship:(NSRelationshipDescription *)relationship predicate:childPredicate parent:self inContext:self.managedObjectContext + dataStack:dataStack completion:nil]; } From cbd55ff7017fb37a2237819d895edebf048cede6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvis=20Nu=C3=B1ez?= Date: Tue, 17 Feb 2015 19:14:35 +0100 Subject: [PATCH 2/2] Update Kipu.podspec --- Kipu.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kipu.podspec b/Kipu.podspec index c4101a08..4a0d4d3f 100755 --- a/Kipu.podspec +++ b/Kipu.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Kipu" -s.version = "0.4.1" +s.version = "0.4.2" s.summary = "A cape, a sword and networking superpowers for your Core Data models" s.description = <<-DESC This is a category that eases your every day job of parsing an API and getting it into Core Data.