1

I'm trying to use Apple's CoreDataCloudkitDemo app. I've only changed the app settings per their README document. On running the demo, I'm getting the error: "CloudKit integration requires does not support ordered relationships."

(The weird grammar in the title is included in the app)

The console log shows:

Fatal error: ###persistentContainer: Failed to load persistent stores:Error Domain=NSCocoaErrorDomain Code=134060 "A Core Data error occurred." UserInfo={NSLocalizedFailureReason=CloudKit integration requires does not support ordered relationships. The following relationships are marked ordered:  
Post: attachments  

There is the same error for the "Tags" entity.

I'm using Xcode 11.0 beta 4 (11M374r).

I've only changed the bundle identifier, and set my Team Id.

I removed the original entitlements file - no errors in resulting build.

I've not changed any code from the original.

Does anyone have a workaround, or preferably, a fix? Or did I do something wrong?

Thanks

ICL1901
  • 7,632
  • 14
  • 90
  • 138

1 Answers1

3

Firstly, select CoreDataCloudKitDemo.xcdatamodeld -> Post -> RelationShips, select attachments relationship, on the Inspect panel, deselect Ordered, then do the same thing on the tags relationship.

Secondly, there will be some errors in the code now, because we unchecked the Ordered option, the property of attachments and tags in the generated NSManagedObject may changed from NSOrderedSet? to NSSet?. So we could change these error lines of code like below:

Origin: guard let tag = post?.tags?.object(at: indexPath.row) as? Tag else { return cell }

Changed: guard let tag = post?.tags?.allObjects[indexPath.row] as? Tag else { return cell }

Finally, you can run the code now. ;-)


Further more, on WWDC19 Session 202, the demo shows they set both attachments and tags relationships as Unordered, so I think there's something wrong in the given demo project.

Kaixin Lian
  • 204
  • 2
  • 5
  • 2
    Here is a patch to make the example project work: https://github.com/ralfebert/SynchronizingALocalStoreToTheCloud/commit/e836893f5a669390090638d89a4f19021e1d2b11 (using allObjects works, but it's a bit dangerous because the order is undefined) – Ralf Ebert Aug 02 '19 at 13:22
  • 1
    I also had to explicitly set the iCloud container id, otherwise it gets a different one for iOS and Catalyst which leads to a build error: https://github.com/ralfebert/SynchronizingALocalStoreToTheCloud/commit/c6306c30864422c2f6cb0cecb56c2b2374e5e6e0 – Ralf Ebert Aug 02 '19 at 13:25
  • I submitted a bug report about the problem (FB6902557) – Ralf Ebert Aug 02 '19 at 13:32
  • @RalfEbert That's cool!!! Thanks a lot! I'm now using this solution and using the create date to sort the items. – Kaixin Lian Aug 08 '19 at 07:00