iosswiftcore-datacorestore

CoreStore update relationships by deleting objects via transaction.edit does not work


I would like to update my core data object by deleting some objects in relationships.

I know CoreStore provides few method update and delete. My question is can I delete by using update functionality?

let john: MyPersonEntity ...
jane.removeFromFriends(john) // Removing john form NSSet

CoreStore.perform(
    asynchronous: { (transaction) -> Void in

        let jane = transaction.edit(jane)! // Assuming that this is a proxy and context will be saved with no john.

    },
    completion: { _ in }
)

Or do I need to remove john like this from the relationships.

let john: MyPersonEntity = jane.getJohnObject() // Returns john object from NSSet.

CoreStore.perform(
    asynchronous: { (transaction) -> Void in
        transaction.delete(john)
    },
    completion: { _ in }
)

Solution

  • Short no, as John is a Entinity. John needs to be deleted. There is no further action necessary if the relation uses the default nullify rule.