Skip to content
An RSS, Atom and JSON Feed parser written in Swift
Swift Other
  1. Swift 99.6%
  2. Other 0.4%
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example iOS Updated project to Swift 4.2 Dec 12, 2018
Example macOS Fixed cannot force unwrap value of non-optional type 'FeedParser' on … Jun 10, 2018
Example tvOS Updated project to Swift 4.2 Dec 12, 2018
FeedKit.xcodeproj Avoid reencoding all incoming data to UTF-8 Feb 25, 2019
Sources Bumped project to version to 8.1.1 Mar 15, 2019
Tests Correct file permissions as per #77 #82 Feb 23, 2019
.gitignore Initial commit May 15, 2016
.swift-version Bumped .swift-version to 4.2 Dec 12, 2018
.travis.yml Removed --verbose parameter from pod lib lint Dec 12, 2018
CHANGELOG.md Bumped project to version to 8.1.1 Mar 15, 2019
FeedKit.paw Added FeedKit.paw Jun 13, 2017
FeedKit.png Added FeedKit header Sep 9, 2017
FeedKit.podspec Bumped project to version to 8.1.1 Mar 15, 2019
INSTALL.md Updated INSTALL.md for version 8.0 Jun 10, 2018
LICENSE
Package.swift Update Package.swift to support Swift 4.2 Feb 17, 2019
README.md Updated README badges Feb 23, 2019

README.md

FeedKit

build status cocoapods compatible carthage compatible language swift

Features

Requirements

xcode ios tvos watchos mac os mac os

Installation >> instructions <<

Usage

Build a URL pointing to an RSS, Atom or JSON Feed.

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

Get an instance of FeedParser

let parser = FeedParser(URL: feedURL) // or FeedParser(data: data) or FeedParser(xmlStream: stream)

Then call parse or parseAsync to start parsing the feed...

A common scenario in UI environments would be parsing a feed asynchronously from a user initiated action, such as the touch of a button. e.g.

// Parse asynchronously, not to block the UI.
parser.parseAsync(queue: DispatchQueue.global(qos: .userInitiated)) { (result) in
    // Do your thing, then back to the Main thread
    DispatchQueue.main.async {
        // ..and update the UI
    }
}

Remember, you are responsible to manually bring the result closure to whichever queue is apropriate. Usually to the Main thread, for UI apps, by calling DispatchQueue.main.async .

Alternatively, you can also parse synchronously.

let result = parser.parse()

Parse Result

Whichever the case, if parsing succeeds you should now have a Strongly Typed Model of an RSS, Atom or JSON Feed.

switch result {
case let .atom(feed):       // Atom Syndication Format Feed Model
case let .rss(feed):        // Really Simple Syndication Feed Model
case let .json(feed):       // JSON Feed Model
case let .failure(error):   
}

Parse Success

You can check if a Feed was successfully parsed or not.

result.isSuccess    // If parsing was a success
result.isFailure    // If parsing failed
result.error        // An error, if any

Model Preview

Safely bind a feed of your choosing:

You may find the example bellow useful, if you're dealing with only a single type of feed.

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

Then go through it's properties:

The RSS and Atom feed Models are rather extensive throughout the supported namespaces. These are just a preview of what's available.

RSS

feed.title
feed.link
feed.description
feed.language
feed.copyright
feed.managingEditor
feed.webMaster
feed.pubDate
feed.lastBuildDate
feed.categories
feed.generator
feed.docs
feed.cloud
feed.rating
feed.ttl
feed.image
feed.textInput
feed.skipHours
feed.skipDays
//...
feed.dublinCore
feed.syndication
feed.iTunes
// ...

let item = feed.items?.first

item?.title
item?.link
item?.description
item?.author
item?.categories
item?.comments
item?.enclosure
item?.guid
item?.pubDate
item?.source
//...
item?.dublinCore
item?.content
item?.iTunes
item?.media
// ...

Refer to the documentation for the complete model properties and descriptions

Atom

feed.title
feed.subtitle
feed.links
feed.updated
feed.authors
feed.contributors
feed.id
feed.generator
feed.icon
feed.logo
feed.rights
// ...

let entry = feed.entries?.first

entry?.title
entry?.summary
entry?.authors
entry?.contributors
entry?.links
entry?.updated
entry?.categories
entry?.id
entry?.content
entry?.published
entry?.source
entry?.rights
// ...

Refer to the documentation for the complete model properties and descriptions

JSON

feed.version
feed.title
feed.homePageURL
feed.feedUrl
feed.description
feed.userComment
feed.nextUrl
feed.icon
feed.favicon
feed.author
feed.expired
feed.hubs
feed.extensions
// ...

let item = feed.items?.first

item?.id
item?.url
item?.externalUrl
item?.title
item?.contentText
item?.contentHtml
item?.summary
item?.image
item?.bannerImage
item?.datePublished
item?.dateModified
item?.author
item?.url
item?.tags
item?.attachments
item?.extensions
// ...

Refer to the documentation for the complete model properties and descriptions

License

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

You can’t perform that action at this time.