Global identifiers? - iCloud + Core Data + Ensembles - duplicates when deleting objects

I am trying to implement iCloud sync in a Core Data application. I am not a programming professional, and this is a really cutting-edge topic that I learned ... I found that Core Data Sync Framework is “Drum McCormack Ensembles”. It seems to make iCloud Sync a lot easier.

I integrated it into my application and synchronization works very well while I add new objects to my Core Data model. But when I delete an object, it creates duplicates. And then duplicates the duplicates. As a result, I had the same Entry (object) as 3-4 times ...

Why? What am I doing wrong? I did some research, and I guess that global identifiers can solve this?

What are global identifiers? I guess they help avoid duplicates !? But how to install it? I really do not know, I did a lot of research, but could not find the answer to this question.

Thanks for the help!

Update: Thanks for the help! I read the readme and the book, but since I'm starting, not everything is clear to me.

I think I now understand the use of global identifiers in ensembles, but I don’t know if I will do it right.

If I understand correctly, I need to assign an identifier for each object. I can do this by storing it in an attribute. This identifier can be any if it is unique, and NSString?

, , , , .. Master-Detail-View Xcode Core Data. Core Data , NSDate. - . "+", , , .

, , . , ,

/// I did find that to use as identifier !?

NSString *taskUniqueStringKey = newManagedObject.objectID.URIRepresentation.absoluteString;

/// and store it in the attribute.

[newManagedObject setValue:taskUniqueStringKey forKey:@"coreDataObjectID"]; 

:

- (NSArray *)persistentStoreEnsemble:(CDEPersistentStoreEnsemble *)ensemble globalIdentifiersForManagedObjects:(NSArray *)objects
{

return [objects valueForKeyPath:@"coreDataObjectID"];;

}

, . ? ? awakeFromInsert!?

, . - , , . ? , , , , , - , [NSDate date] .

, , Ensembles NSString, NSDate!? date, gloabl identifier? , , ?

Ensembles . , iCloud, , , , . ! , , , , , , , . , ? , .

, :

- (void)syncWithCompletion:(void(^)(void))completion
{
if (self.ensemble.isMerging) return;


if (!self.ensemble.isLeeched) {
    [self.ensemble leechPersistentStoreWithCompletion:^(NSError *error) {
        if (error) NSLog(@"Error in leech: %@", error);

        if (completion) completion();
    }];
}
else {
    [self.ensemble mergeWithCompletion:^(NSError *error) {

        if (completion) completion();
    }];
}

, ? , " - , "?

, , . , . , . : Core Data . "sync now".

[self syncWithCompletion:NULL];

, . Ensembles? . , ?

! - !;)

+4
2

, - , , , .

, . , .

, . , , , . , , .

- . CDEPersistentStoreEnsemble, Ensembles , , .

? , UUID, .

awakeFromInsert. . ( : , fetch, , .)

README GitHub leanpub.

Update

:

, . .

NSManagedObjectID , . - .

, NSUUID - . .

, , . - - . , .

, . , createDate + text. ( , , , , .) UUID .

, awakeFromInsert. . , .

NSDate - description, double timeIntervalSince1970 . ( : , , .)

, : syncWithCompletion:.

: , , , . :

  • .
  • , , . . "Sample1", "Sample2" ..
+5

, , .

1 CDEPersistentStoreEnsemble delegate (. README)

- (NSArray *)persistentStoreEnsemble:(CDEPersistentStoreEnsemble *)ensemble 
    globalIdentifiersForManagedObjects:(NSArray *)objects {
    return [objects valueForKeyPath:@"yourUniqueIdentifier"];
}

2 NSManagedObject

- (void)awakeFromInsert {
    [super awakeFromInsert];

    if (!self.yourUniqueIdentifier) {
        self.yourUniqueIdentifier = [[NSUUID UUID] UUIDString];
    }
}

awakeFromInsert , , .

, , - . . . awakeFromInsert ?.

+3

All Articles