CSFeedKit 0.2.1

CSFeedKit 0.2.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Aug 2016

Maintained by Cătălin Stan.



CSFeedKit 0.2.1

An RSS feed generator and parser for macOS. Swift and Objective-C compatible.

Installation

Install using CocoaPods by adding this line to your Podfile:

use_frameworks!

target 'MyApp' do
  pod 'CSFeedKit'
end

Creating an RSS Feed

The example below creates an RSS feed and prints the resulting XML string.

// Create a channel
let channel = CSRSSFeedChannel.init(title: "My RSS feed", link: "http://my.rss.feed/", description: "My first CSFeedKit RSS feed")
channel.category = "Examples"

// Add an item to the channel
let item = CSRSSFeedItem(title: "Item" , link: "http://my.rss.feed/item", description: "The coolest item so far.");
item1.creator = NSFullUserName()
channel.items.addObject(item)

// Create the feed
let feed = CSRSSFeed()

// Add the channel to the feed
feed.channels.addObject(channel)

// Output the XML
print ( feed.XMLDocument().XMLStringWithOptions(NSXMLNodePrettyPrint))

Parsing an RSS feed

The following prints out the titles and URLs of the items in the Hacker News RSS feed.

do {
    // Get the XML string (don't do it like this in the real-world ;) )
    let xmlString = try NSString.init(contentsOfURL: NSURL(string: "https://news.ycombinator.com/rss")!, encoding: NSUTF8StringEncoding)

    // Init the feed
    let feed = try CSRSSFeed.init(XMLString: xmlString as String)

    // Print channel info
    let channel = feed.channels.firstObject as! CSRSSFeedChannel
    print("channel: \(channel.title)")

    // Print the items
    for (_, item) in channel.items.enumerate() {
        var rssItem = item as! CSRSSFeedItem
        print(" * \(rssItem.pubDate) - \(rssItem.title) (\(rssItem.link))")
    }
} catch {
    print(error)
}

What’s Next

Run the built-in example: https://github.com/thecatalinstan/CSFeedKit/blob/master/CSFeedKitExamples/CSFeedKitExamples/main.swift

Check out the complete documentation on CocoaDocs.