Swiftpack.co - thecatalinstan/CSFeedKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by thecatalinstan.
thecatalinstan/CSFeedKit 1.0.0
An RSS feed generator and parser library for macOS. Swift and Objective-C compatible.
⭐️ 5
🕓 48 weeks ago
macOS
.package(url: "https://github.com/thecatalinstan/CSFeedKit.git", from: "1.0.0")

Version Status Platform Carthage compatible MIT License

CSFeedKit

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

Installation

You can install by either cloning the repo directy and adding the included project or by using one of the package managers, as described below.

Swift Package Manager

Add the package to your project's dependencies. If you have a Package.swift, it should look similar to this:

dependencies: [
    .package(name: "CSFeedKit", url: "https://github.com/thecatalinstan/CSFeedKit", from: "1.0.0"),
]

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 two items to the channel
var items = Array<CSRSSFeedItem>()
items.append(CSRSSFeedItem(title: "Item 1" , link: "http://my.rss.feed/item1", description: "The coolest item so far."))
items.append(CSRSSFeedItem(title: "Item 2" , link: "http://my.rss.feed/item2", description: "An even cooler item."))
channel.items = items

// Create the feed
let feed = CSRSSFeed()

// Add the channel to the feed
feed.channels = [channel]

// Output the XML
print(feed.xmlElement().xmlString(options: .nodePrettyPrint))

Parsing an RSS feed

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

// Get the XML string (don't do it like this in the real-world ;) )
let xmlString = try String(contentsOf: URL(string: "https://news.ycombinator.com/rss")!)

// Init the feed
let feed = try CSRSSFeed(xmlString: xmlString)

// Print channel info
let channel = feed.channels[0]
print("channel: \(channel.title) - \(channel.pubDate ?? Date.distantPast)")

// Print the items
for item in channel.items {
    print(" * \(item.pubDate ?? Date.distantPast) - \(item.title) (\(item.link))")
}

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.

GitHub

link
Stars: 5
Last commit: 48 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

48 weeks ago

Released on Tuesday, June 22, 2021.

This release adds support for the Swift Package Manager. It also updates the projects to Xcode 12.5 recommended build settings. Minimum macOS version is now 10.9, mainly for Xcode 12 compatibility, should still work fine on macOS >= 10.7.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics