mentrena / SyncKit

Automatic CloudKit synchronization
https://mentrena.github.io/SyncKit/
MIT License
508 stars 59 forks source link

Many-to-many relationships and Core Data #174

Open pedrommcarrasco opened 2 years ago

pedrommcarrasco commented 2 years ago

Are many-to-many relationships on Core Data still unsupported? 🤔

mentrena commented 2 years ago

Correct, CloudKit doesn't support them. CloudKit only supports many-to-one relationships by using a reference in each of the "many" records to the "one" record (see: https://developer.apple.com/documentation/cloudkit/ckrecord/reference)

pedrommcarrasco commented 2 years ago

Out of curiosity, does NSPersistentCloudKitContainer support them? - didn't see much information around 🤔

mentrena commented 2 years ago

That's a good question, the most I found is this:

All relationships must be optional. Due to operation size limitations, CloudKit may not save relationship changes atomically.
All relationships must have an inverse, in case the records synchronize out of order.
CloudKit doesn’t support the Deny deletion rule.

which doesn't specifically say it doesn't support many-to-many, although in my head inverse relationships don't make sense in the case of many-to-many relationships. But I haven't tried it myself –nor have I really used NSPersistentCloudKitContainer.

Actually, after reading the docs for CKRecord again I see properties can be arrays of references, so I think it should be possible to support many-to-many relationships. I'll have a try at adding support as time allows :)