FeedParser 3.1.1

FeedParser 3.1.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jul 2016
SPMSupports SPM

Maintained by Nuno Manuel Dias.



  • By
  • Nuno Manuel Dias

FeedParser

An RSS and Atom feed parser written in Swift

Deprecated Notice

FeedParser and been renamed FeedKit and moved to a new repository.

The sole reason for deprecating the FeedParser repository lies under the need to rename the framework while keeping a consistent use of it’s new name. The new repository FeedKit will be under active development and maintenance.

Features

Requirements

Usage

Feed Parsing

RSS

import FeedParser

let URL = NSURL(string: "http://images.apple.com/main/rss/hotnews/hotnews.rss")!

FeedParser(URL: URL)?.parse({ (result) in
    result.rssFeed // An `RSSFeed` model
})

Atom

FeedParser(URL: URL)?.parse({ (result) in
    result.atomFeed // An `AtomFeed` model
})

Aditional initializers can also be found for NSData and NSInputStream objects.

Parse Result

Multiple FeedType’s and, or Error handling can be acomplished using the Result enum

FeedParser(URL: URL)?.parse({ (result) in

    switch result {
    case .RSS(let rssFeed):
        print(rssFeed) // An `RSSFeed` model
    case .Atom(let atomFeed):
        print(atomFeed) // An `AtomFeed` model
    case .Failure(let error):
        print(error) // An `NSError` object
    }

})

Model Preview

RSSFeed

FeedParser(URL: URL)?.parse({ (result) in

    guard let feed = result.rssFeed where result.isSuccess else {
        print(result.error)
        return
    }

    print(feed.title)                      // The feed's `Title`
    print(feed.items?.count)               // The number of articles
    print(feed.items?.first?.title)        // The feed's first article `Title`
    print(feed.items?.first?.description)  // The feed's first article `Description`
    print(feed.items?.first?.pubDate)      // The feed's first article `Publication Date`

})

Refer to the RSSFeed documentation for the complete model properties and description

AtomFeed

FeedParser(URL: URL)?.parse({ (result) in

    guard let feed = result.atomFeed where result.isSuccess else {
        print(result.error)
        return
    }

    print(feed.title)                    // The feed's `Title`
    print(feed.entries?.count)           // The number of articles
    print(feed.entries?.first?.title)    // The feed's first article `Title`
    print(feed.entries?.first?.summary)  // The feed's first article `Summary`
    print(feed.entries?.first?.updated)  // The feed's first article `Updated Date`

})

Refer to the AtomFeed documentation for the complete model properties and description

Background Parsing

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), {
    // Run parsing in a background thread
    FeedParser(URL: URL)?.parse({ (result) in
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            // Perform updates to the UI
        })
    })
})

License

FeedParser is released under the MIT license. See LICENSE for details.