Skip to content
/ FeedKit Public

FeedKit is a Swift library for Parsing and Generating RSS, Atom, and JSON feeds.

License

Notifications You must be signed in to change notification settings

nmdias/FeedKit

Repository files navigation


FeedKit is a Swift library for Parsing and Generating RSS, Atom, and JSON feeds.

FeedKit v10 (Beta) ⚠️

FeedKit v10 is in beta and introduces a new parsing engine, features, and improvements. It may contain bugs that still need to be ironed out and unit tested.

It should be stable enough 👀, but if stable enough is not enough, consider using v9.

Features

Feed Parsing

The fetching, loading and parsing of feeds can be made with a dedicated type, such as RSSFeed, AtomFeed and JSONFeed, or a universal type Feed.

Dedicated

When you know the type of feed to be parsed, use a dedicated type.

try await RSSFeed(urlString: "https://developer.apple.com/news/rss/news.rss")

Universal

When you don't know the type of feed, use the universal Feed enum type.

The Feed enum type handles RSS, Atom and JSON feeds and will determine the type of feed before parsing occurs.

// Fetch and parse any feed type
let feed = try await Feed(urlString: "https://surprise.me/feed")

// Use a switch to get the resulting parsed feed model
switch feed {
case let .atom(feed): // An AtomFeed instance
case let .rss(feed): // An RSSFeed instance
case let .json(feed): // A JSONFeed instance
}

Initializers

All feed types have multiple initializers. They provide a flexible way to fetch and parse feeds from the most common sources.

Show

From a URL String:

init(urlString: String) async throws

From a URL, handling both local file URLs and remote URLs:

init(url: URL) async throws

From a local file URL:

init(fileURL url: URL) throws

From a remote URL:

init(remoteURL url: URL) async throws

From an XML or JSON String:

init(string: String) throws

From raw Data:

init(data: Data) throws

Feed Generation

To generate an XML string for any given XML feed, create an instance of an RSSFeed or AtomFeed and populate it with the necessary data.

let feed = RSSFeed(
  channel: .init(
    title: "Breaking News",
    link: "http://www.breakingnews.com/",
    description: "Get the latest updates as they happen.",
    // ...
    items: [
      .init(
        title: "Breaking News: All Hearts are Joyful",
        link: "http://breakingnews.com/2025/01/09/joyful-hearts",
        description: "A heartwarming story of unity and celebration."
        // ...
      ),
    ]
  )
)

Then call toXMLString(formatted:) to generate the XML string.

let xmlString = try feed.toXMLString(formatted: true)
Output
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Breaking News</title>
    <link>http://www.breakingnews.com/</link>
    <description>Get the latest updates as they happen.</description>
    <item>
      <title>Breaking News: All Hearts are Joyful</title>
      <link>http://breakingnews.com/2025/01/09/joyful-hearts</link>
      <description>A heartwarming story of unity and celebration.</description>
    </item>
  </channel>
</rss>

Feed Models

The RSS, Atom, and JSON feed models are highly comprehensive, especially when combined with all the supported namespaces. Below is a small preview of what’s available.

Preview

RSS

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

let item = channel.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
// ...

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
// ...
entry?.media
entry?.youTube

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
// ...

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
// ...

Installation

To add FeedKit to your Xcode project, follow these steps:

  • Open your project in Xcode and go to the "File" menu.
  • Select "Add Package Dependencies…"
  • Enter the "Package URL": https://github.com/nmdias/FeedKit
  • Select "Add Package"

License

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