ChannelViewController info


#1

I noticed that somewhere along the line of the last few chapters (not sure in which chapter this actually popped up), the table view for ChannelViewController no longer displays the information. I did some investigating with lldb, and it seems that right as the channel finishes parsing itself (i.e., parser:didEndElement:…, if ([elementName isEqual:@“channel”]) …), the title and infoString properties are set like they should be. But by the time it gets from that point to the tableview, the strings are nil. I can’t find where or why it’s getting removed. Is it something I (accidentally) broke, or is this a design issue with the changes over the last few chapters in the book?

Thank you!


#2

I think that element in the XML or JSON is named differently - try scanning the incoming data and making sure your parsing code is identifying the correct key.


#3

It seems to be scanning the correct keys. I’ll post my code when I get back to my computer (posting from my phone right now).

Also, I should add that, for Apple’s RSS feed, it’s showing the info for the first table cell in ChannelViewController, but for the feed for this forum, both cells are blank.


#4

Well, after a couple of hours of tracing RSSChannel with the debugger, I found the problem:

When we are parsing the JSON data from Apple, we don’t tell the RSSChannel to read anything for the infoString. So I added this line within -readFromJSONDictionary: in RSSChannel

[self setInfoString:[[feed objectForKey:@"rights"] objectForKey:@"label"]];

And for the RSS feed from this forum’s servers, in -fetchRSSWithCompletion:, we make a copy of the cachedChannel. The first time this application is run, the cachedChannel is empty, which makes the copy empty as well. Then in the completion block we add the new items returned from the server via the completion block (RSSChannel *obj) with the copy, which is still empty. Since it is empty, it has no knowledge of any title or infoString. “obj” does, but it does not pass this information along to the copy – only a sorted version of its items array. When we actually get to archiving this copy, it still knows nothing of a title or infoString.

Then the next time the app is run, or we switch screens and the data gets downloaded again, our code unarchives this very same cached version of RSSChannel, which, again, knows nothing of a title or infoString.

The solution is simple: just add these two lines to -addItemsFromChannel:

[self setTitle:[otherChannel title]];
[self setInfoString:[otherChannel infoString]];

Perhaps this was simply overlooked when writing the code for the book?

I’ve really enjoyed this book, by the way. After about 6 months of reading it due to other obligations and not having a lot of time to read it, I have learned so much and am almost ready to start with my own applications (just one more chapter).