FeedParser 3.1.1

FeedParser 3.1.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2016年7月
SPM支持 SPM

Nuno Manuel Dias 维护。



  • Nuno Manuel Dias

FeedParser

一个用 Swift 编写的 RSS 和 Atom 提要解析器

弃用通知

FeedParser 已更名为 FeedKit 并移至新仓库。

弃用 FeedParser 仓库的唯一原因是需要在保留新名称一致使用的同时重命名框架。新仓库 FeedKit 将进行积极开发和维护。

特性

要求

用法

提取内容

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
})

还可以找到针对 NSDataNSInputStream 对象的额外初始化程序。

解析结果

可以使用 Result 枚举完成多个 FeedType 和 / 或 错误处理

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
    }

})

模型预览

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`

})

有关完整模型属性和描述,请参阅 RSSFeed 文档。

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`

})

请参阅 AtomFeed 的文档以获取完整的模型属性和描述

后台解析

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
        })
    })
})

许可

FeedParser 使用 MIT 许可发布。详情请见 LICENSE