URL 抓取初始化器依赖 URLSession,在 WASI 上不可用,需改用 fileURL、string 或 data 初始化器;README 只给出 Xcode 图形化添加方式,未提供 Package.swift 依赖写法
FeedKit
nmdiasMIT活跃维护Swift 编写的 RSS、Atom 和 JSON 订阅源解析与生成库,帮你在 iOS/macOS 应用里快速读取和输出各类 feed。
FeedKit is a Swift library for Reading and Generating RSS, Atom, and JSON feeds.
在 Xcode 中选择 File > Add Package Dependencies…,Package URL 填 https://github.com/nmdias/FeedKitREADME 未说明;这是 Swift 库,不涉及 GPU 或显存要求
Swift 库,读写 RSS、RDF、Atom、JSON 四类订阅源,省去自己解析和拼装
Swift 编写的 RSS、Atom 和 JSON 订阅源解析与生成库,帮你在 iOS/macOS 应用里快速读取和输出各类 feed。
核心能力
- 统一 Feed 枚举自动识别 RSS/RDF/Atom/JSON 类型
- 支持 Dublin Core、iTunes、Media RSS 等十余种命名空间
- 从 URL、本地文件、字符串或 Data 多种来源初始化
- 用 toXMLString 和 toJSONString 生成订阅源字符串
- 提供 FeedType 枚举,不解析即可判断订阅源类型
容易踩的坑
- 10.10.2最新正式版2026-10-29 · 2026-10-29 09:38 UTC
What's Changed
- Record the 10.10.1 parse benchmark by @nmdias in https://github.com/nmdias/FeedKit/pull/260
- Inspect 1024 bytes when detecting the feed type (#261) by @nmdias in https://github.com/nmdias/FeedKit/pull/262
Full Changelog: https://github.com/nmdias/FeedKit/compare/10.10.1...10.10.2
- 10.10.12026-10-25 · 2026-10-25 13:29 UTC
查看更新说明
What's Changed
- Modernize the example app's SwiftUI by @nmdias in https://github.com/nmdias/FeedKit/pull/257
- Build the example app in CI by @nmdias in https://github.com/nmdias/FeedKit/pull/258
- Modernize CI workflows by @nmdias in https://github.com/nmdias/FeedKit/pull/259
Full Changelog: https://github.com/nmdias/FeedKit/compare/10.10.0...10.10.1
- 10.10.02026-10-24 · 2026-10-24 11:19 UTC
查看更新说明
What's Changed
- Build for WASI without Foundation networking by @nmdias in https://github.com/nmdias/FeedKit/pull/256
Full Changelog: https://github.com/nmdias/FeedKit/compare/10.9.5...10.10.0
- 10.9.52026-10-24 · 2026-10-24 10:14 UTC
查看更新说明
What's Changed
- Read seconds-less RFC 822 dates with a numeric offset by @nmdias in https://github.com/nmdias/FeedKit/pull/255
Full Changelog: https://github.com/nmdias/FeedKit/compare/10.9.4...10.9.5
- 10.9.42026-09-27 · 2026-09-27 18:11 UTC
查看更新说明
What's Changed
- Add a parse benchmark and a performance tracker by @nmdias in https://github.com/nmdias/FeedKit/pull/243
- Fix XMLError.cdataDecoding error code by @nmdias in https://github.com/nmdias/FeedKit/pull/244
- Fix crash when serializing a permissive date by @nmdias in https://github.com/nmdias/FeedKit/pull/245
- Parse feed dates with static ParseStrategy caches by @nmdias in https://github.com/nmdias/FeedKit/pull/251
- Record the 10.9.4 parse benchmark by @nmdias in https://github.com/nmdias/FeedKit/pull/252
Full Changelog: https://github.com/nmdias/FeedKit/compare/10.9.3...10.9.4
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
FeedKit is a Swift library for Reading and Generating RSS, RDF, Atom, and JSON feeds.
Features
- Atom
- RSS
- RDF (RSS 1.0 and 0.90)
- JSON
- Namespaces
- Examples
- Documentation
- Unit Tests
Feed Reader
Feed reading can be made with a dedicated type, such as RSSFeed, RDFFeed, AtomFeed and JSONFeed, or a universal type Feed.
Dedicated
When you know the type of feed to be read, 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, RDF, Atom and JSON feeds and will determine the type of feed before reading, parsing and decoding occurs.
// Read any type of feed
let feed = try await Feed(urlString: "https://surprise.example/feed")
// Use a switch to get the resulting feed model
switch feed {
case let .atom(feed): // An AtomFeed instance
case let .rss(feed): // An RSSFeed instance
case let .rdf(feed): // An RDFFeed instance
case let .json(feed): // A JSONFeed instance
}
Manual Feed Type Detection
The universal Feed enum above automatically determines the feed type, so you generally don't need to do it manually. However, using a FeedType enum can be helpful when you want to identify the type of feed without
the overhead of parsing and decoding.
let feedType = try FeedType(data: data)
// Detect feed type
switch feedType {
case .rss: // RSS feed detected
case .rdf: // RDF feed detected
case .atom: // Atom feed detected
case .json: // JSON feed detected
}
// Or feed content type
if feedType.isXML {
// XML feed detected
} else if feedType.isJSON {
// JSON feed detected
}
Initializers
All feed types conform to FeedInitializable, sharing multiple common initializers. They provide a flexible way to read feeds from the most common sources.
Note: The URL-fetching initializers require
URLSession, which Foundation does not provide on WASI. On WASI, use the localfileURL:,string:, anddata:initializers.
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 Generator
XML
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.example/",
description: "Get the latest updates as they happen.",
// ...
items: [
.init(
title: "Breaking News: All Hearts are Joyful",
link: "http://breakingnews.example/2025/01/09/joyful-hearts",
description: "A heartwarming story of unity and celebration."
// ...
),
]
)
)
Then call toXMLString(formatted:) to generate the XML string.
try feed.toXMLString(formatted: true)
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Breaking News</title>
<link>http://www.breakingnews.example/</link>
<description>Get the latest updates as they happen.</description>
<item>
<title>Breaking News: All Hearts are Joyful</title>
<link>http://breakingnews.example/2025/01/09/joyful-hearts</link>
<description>A heartwarming story of unity and celebration.</description>
</item>
</channel>
</rss>
JSON
In the same way, you can create an instance of a JSONFeed, populate it, and then call toJSONString(formatted:) to generate a JSON string.
try feed.toJSONString(formatted: true)
Feed Models
The RSS, RDF, 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.
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
// ...
RDF
feed.channel?.title
feed.channel?.link
feed.channel?.description
// ...
feed.channel?.dublinCore
feed.channel?.syndication
// In RSS 1.0 the items are siblings of the channel
let item = feed.items?.first
item?.title
item?.link
item?.description
// ...
item?.dublinCore
item?.content
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"
Performance
Parsing speed across versions is tracked in PERFORMANCE.md. To measure and add a row:
cd Benchmarks
./bench.sh
License
FeedKit is released under the MIT license. See LICENSE for details.