CloudKit don't sync Relationships

CloudKit + Core Data

I created two entities

  • Credit Card
    • Relationship: transactions
  • Transaction
    • Relationship: creditcard

Configuration: Default is already set "used with CloudKit"

Problem

The relationships don't sync. For example, on 1st device.

let creditCard = CreditCard(context: viewContext)
creditCard.name = "First Card"

let firstTransaction = CCTransaction(context: viewContext)
firstTransaction.price = "First Transaction"
firstTransaction.price = 100

creditCard.addToTransactions(firstTransaction)
firstTransaction.creditcard = creditCard

try! viewContext.save()

// Check transactions
print(creditCard.transactions.count) // 1

on 2nd device after synced

@FetchRequest(
        sortDescriptors: [NSSortDescriptor(keyPath: \CreditCard.name, ascending: true)],
        animation: .default)
    var creditcards: FetchedResults<CreditCard>

// Check transactions
ForEach(creditcards) { creditcard in 
  Card("")
    .onTapGesture {
      print(creditCard.transactions.count) // will have a value of 0 except the device that records the relationship.
    }
}

It looks like the relationship never syncs

Data Model

CloudKit don't sync Relationships
 
 
Q