Cloudkit constraint issue

Hello All,

Currently we have an app with coredata as storage mechanisms and it works fine. Now we want to move to coredata with cloudkit and found unique constraints are not supported by cloudkit.

Can someone suggest how to enable cloudkit and still enforce unique constraints. Thanks in advance

Vinoth

Post not yet marked as solved Up vote post of vmvinoth Down vote post of vmvinoth
666 views

Replies

I struggled with this a year ago. In the end I restructured my model so it works without unique constraints.

For example, you may have a many-to-many relationship between entities Color and Animal (an animal may have multiple colours, and vice-versa: a specific colour may be found on various animals). Without unique constraints, you can fetch animals by colour like this:

    if colorFilter != .noValue {
      // any animal where color in colors relationship contains value
      predicates.append(NSPredicate(format: "ANY colors.color == %@", colorFilter.rawValue))
    }