Вопрос

I found many tutorials & articles over internet for core data but I am making sample app that is realtime & more useful to beginner. You can find the sample code here.

The core data structure core data structure is like this.

I make entries to artists, albums & songs. But the problem is later editing done to already added Artists is not reflecting to albums.

What am i missing to do so?

To reproduce this issue I request to download the project & run it.

  • Make some entries to Artists, Albums, & Songs.
  • Then later on goto to Artist tab & edit some of the the Artist entries.
  • Now goto Album tab. You will see the artists name same as old ones for associated Album entries.

This is the problem. Ideally I should see new entries there.

I want some genuine way to achieve this

Это было полезно?

Решение

Not sure about your instructions on reproducing the issue as the Album tab doesn't show Artist's names, until you click the Genre button, and then it shows the artists names correctly. The spot where I saw an error was in going to the Song tab.

From a brief look at what's happening I believe this problem is because you are displaying the artist name by the NSString saved into your song called songArtist as opposed to getting the artist name from a referenced artist entity.

CoreData will not update song.artistName NSString just because you changed artist.artistName. It doesn't know that those 2 strings are related. You will need to do that update yourself.

Alternatively, you need to refresh the information from the Song entity to set the new variable of Song's artistName.

Hope that makes sense.

/* UPDATE */

Your Song references an Artist, but it is a to-many relationship. I always assumed a Song would only have one artist, so untick the to-many relationship in your CoreData relationship. In which case you should then display the artist name by way of song.artist.artistName. Then when the artist entity is updated the song will be referencing the artist which in turn has the correct info.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top