I want a divorce! (or how do I remove a relationship?)


#1

Yet another noob question.

I’m working on a song writing app. I have a many to many relationship between Song and Lyric objects. If I decide that a lyric I have added to a song isn’t going to work, how do I remove that relationship? I don’t want to delete the lyric, just send it back to the general lyric pool.


#2

The relation parameters are optional, right? So, you need to set it nil, and you are good to go.

And I want to 10% what you give your (soon to be) ex-wife :stuck_out_tongue:


#3

What property do I need to set to nil? I tried:

lyrics[indexPath.row].song = nil

but that just gives me the error “‘nil’ cannot be assigned to type ‘LinkingObjects’”


#4

The relations are stored in the parent object.

The LinkingObject is an inverse relationship property, you set it on the child and just store a reference to the parent. It’s not nullable.

[The parents decide the divorce, not the child :smile:]