Question about currentString


#1

Going through the chapter and am at the RSSItem.m section. What I don’t understand is how setTitle and setLink is called after the initial setter called in the parser: didFindElement … The foundCharacters appends the currentString but I don’t see how or when the title or link are set to the appended currentString. Some help would be greatly appreciated.

Thanks,
Jeff


#2

I’m still not understanding the currentString use. In the book, it states that because currentString and title/infoString point to the same object, both are updated when currentString is appended. So why isn’t the instance variable, title or infoString, set to nil at the didFinish method when currentString is set to nil?


#3

I’ve asked myself exactly the same thing at that part. Now, looking at it again, it seems more clear to me:

  1. First, in parser:didStartElement: when we set one of our properties (title, infoString) to currentString, we are actually making both pointers point at the same string object, like you just said. The string is just empty at this point, and it has 2 owners (currentString and one of our properties).

  2. Then, in parser:foundCharacters: we append the characters one by one to the string using the currentString pointer. Since our property (title, infoString) points to the same string object, it will be “updated” as well.

  3. At parser:didEndElement: the string is finally complete. Setting currentString to nil doesn’t set the string to nil, but instead makes the pointer currentString point to a nil object. The original string object remains intact because, although it just lost one owner, it is still owned by one of our properties (title, infoString). This happens just because our string properties are of the strong type, meaning of course that they will retail the object they point to, as in this case.

If, otherwise, title or infoString were properties of type weak, they would’ve been set to nil as well.

Cheers,

Gilmar


#4

Thanks, Gilmar. That’s sort what I was starting to conclude. Not having worked with pointers, I don’t trust my thought process at times.