Proxy Object example in Key Value Coding Section

I’m having a hard time understanding the proxy object example (page 193) in this chapter.

The proxy object is created using mutableArrayValueForKey using the key “songs”. The text says that when asked for the count, the proxy object will do the following:

  1. Ask the PlayList object if it has a countOfSongs property
  2. If countOfSongs doesn’t exist, it will return the count for the songs property.

When I tried to replicate this example in a Playground and in an app, it didn’t work this way.

I made a class called Playlist. It initializes with an empty array songs of Strings and a property called countOfSongs set to 2. I create an instance of Playlist called myPlayList, and append four Strings to songs.

I then create arrayProxy using myPlayList.mutableArrayValueForKey(“songs”). The book says that arrayProxy.count should return the value of countOfSongs, since I have a property defined with that name. But instead it returns the count of the array of songs.

What am I missing here?

Thanks for any help.

See KVC for ordered relationship