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?
2 Answers
There are a couple of steps to this.
- You need a datasource, of course.
- 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:
- 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.)
-
Would it work a bit like the example app found here hotcocoa.lastedit.com/www/2009/01/… ?– JoshuaCommented Aug 23, 2009 at 15:03
-
Indeed; except you would probably want to use
NSXMLParser
rather thanNSXMLDocument
. Commented Aug 23, 2009 at 15:18 -
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?– JoshuaCommented Aug 23, 2009 at 15:42
-
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 implementNSXMLParserDelegate
in a suitable class and pass it to anNSXMLParser
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. Commented Aug 23, 2009 at 17:46 -
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 grabup.com/uploads/6a8a297224120cf429d20088fdac918a.png?direct but it doesn't load the feed. Why not? Do I need to change something else?– JoshuaCommented Aug 23, 2009 at 17:54
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
-
Hmmm. Could you share some example code which I could modify?– JoshuaCommented Aug 23, 2009 at 17:01
-
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.– JoshuaCommented Aug 23, 2009 at 17:56
-
2Joshua: That doesn't mean PubSub can't do it. You'll just have to write your own original code. Commented Aug 23, 2009 at 18:18