views:

271

answers:

2

How would I make an NSTableView display an RSS Feed (just one)? I think it would have something to do with NSURL and Setting the Table Views Data Source. But how exactly would I do this?

+3  A: 

There are a couple of steps to this.

  1. You need a datasource, of course.
  2. This datasource needs to be capable of either itself attaching to an RSS feed, reading it, parsing it and turning it into something sensible for display; or:
  3. You need to have a datasource-datasource that encapsulates the network/XML parsing/RSS interpreting bits.

Most likely you'll want something like:

NSTableView <-> MyDatasource <-> MyDownloadHandler

Where MyDownloadHandler takes care of all the downloading and parsing, and notifies MyDatasource as it receives data, which then notifies the table view to redraw itself (or patiently waits for the table view to redraw itself in the course of its normal operations or as the result of a timer firing, or by emitting notifications captured by a controller that asks the table view to redraw itself).

EDIT: This, of course, doesn't actually answer your question...

Specifically you will need an NSURLConnection object to get the RSS feed (either synchronously or async; it can do both if memory serves, if not, there's another class that does.)

You will also need to implement the NSXMLParserDelegate category on a handler object and run an NSXMLParser on your RSS feed. (NSXMLParser can in fact be initialized directly with initWithContentsOfURL:, potentially saving you some time.)

Williham Totland
Would it work a bit like the example app found here http://hotcocoa.lastedit.com/www/2009/01/hot-cocoa-11-twitter-app-iv-cleaning-house/ ?
Joshua
Indeed; except you would probably want to use `NSXMLParser` rather than `NSXMLDocument`.
Williham Totland
I see. So what parts of that would I need to change (except of getting rid of code that it's no longer needed) to make it work with my feed?
Joshua
That would depend. Most of the code can probably be used as it is, but if you choose to go the `NSXMLParser` route, you'll need to implement `NSXMLParserDelegate` in a suitable class and pass it to an `NSXMLParser` created from the data you fetch (or init with the URL) to turn the feed into objects that make sense for your application. That I could not tell you how to do, without a lot more details on your implementation specifics.
Williham Totland
Ok I'll try to use it as it is without going the `NSXMLParser` route. So I tried changing the get Public Feed URL to another feed, as you can see in this picture http://www.grabup.com/uploads/6a8a297224120cf429d20088fdac918a.png?direct but it doesn't load the feed. Why not? Do I need to change something else?
Joshua
What does the Alert say? Knowing the error message *might* be helpful.
Williham Totland
Oh Yeh Sorry, The debugger says `2009-08-24 07:19:07.119 TweetApp[6151:10b] *** -[NSXMLDocument initWithData:options:error:]: nil argument`.
Joshua
Which is Related to this Code. http://www.grabup.com/uploads/a9e183720f252baa5e9ec458cfa7fe94.png?direct
Joshua
The error is in the code that calls both these methods. (The result of one should be passed to the other.)
Williham Totland
Which is here http://www.grabup.com/uploads/6f4589026e31e30d0e8d7657541522e9.png?direct because it calls NSXMLDocument and inithWithData:options:error:. So whats wrong with that code?
Joshua
"both these methods" being `getPublicTimeline` and `updateTimelineWithData:`.
Williham Totland
It seems that it will only work if you login to twitter. Even using the example app without modifications it will not allow you to see the Public Timeline without logging in. Is there some code I need to change to stop it from doing this?
Joshua
How is that an issue? You're not connecting to twitter.
Williham Totland
The two methods are sent to the twitterEngine object, in the sample application, this is created thurough the login process. If you instantiate the twitterEngine yourself it might help. If you saw that you needed to log-in to do something, you should have looked at the related code to see what is being done.
Abizern
Adding an `awakeFromNib` method with the code `twitterEngine = [[HCTwitterEngine alloc] init];` gets rid of the error in the Debugger. But it doesn't actually display the feed in the table view.
Joshua
Keep looking. What else is being done in the login methods that still needs to be done?
Abizern
Updating the Timeline With Data? But that wouldn't change anything because I click the button to make it display the feed and it doesn't.
Joshua
What button are you clicking?
Abizern
The Public Timeline Button. And even I do add the line of code that updates the timeline with data to the `awakeFromNib` method it still does not work.
Joshua
Do you not think that there is a difference between the xml for the Twitter public timeline and the Apple news rss feed?
Abizern
Yes, Probably. But how would I need to modify the code to make it work with the Apple Feed?
Joshua
This is the part where you choose to read the XML programming guide or the PubSub programming guide so you can translate the raw feed into a datasource for the NSTableView.
Abizern
Is this how you do it … http://www.grabup.com/uploads/cdfd1a090f7a875f1b8fd2504de81e4a.png?direct ?
Joshua
+2  A: 

You should take a look at the PubSub.framework:
Apple Developer Connection PubSub Programming Guide
Some features:

  • retrieve feed contents
  • subscribe to feeds
  • Atom/RSS agnostic
  • ...

10.5+ only

weichsel
Hmmm. Could you share some example code which I could modify?
Joshua
I took a look at the example apps for PubSub in the Developer/Examples folder but the app there is a full blown RSS App, when I want it only to display one feed in a Table View.
Joshua
Joshua: That doesn't mean PubSub can't do it. You'll just have to write your own original code.
Peter Hosey