AlamoFuzi

Build Status CocoaPods Compatible License Platform

用于 Alamofire 的 XML/HTML 响应处理器,使用 Fuzi

AlamoFuzi 向 AlamofireDataRequest 类添加了 .responseXML().responseHTML() 响应处理器。两种文档类型都使用 Fuzi 进行序列化,这是在 Swift 中解析 XML/HTML 的首选方法。

要求

安装

将 AlamoFuzi 添加到您的项目最简单的方法是使用 CocoaPods。

使用 CocoaPods

您可以使用 CocoaPods 安装 AlamoFuzi,方法是将其添加到您的 Podfile

platform :ios, '9.0'
use_frameworks!

target 'MyApp' do
pod 'AlamoFuzi', '~> 1.0.0'
end

然后,运行以下命令

$ pod install

手动

只需将 AlamoFuzi.Swift 添加到您的项目即可。 请注意,Fuzi 和 Alamofire 必须已集成到您的项目中。

##使用示例

import Alamofire
import AlamoFuzi

Alamofire.request("http://example.org/").responseHTML { response in
    switch response.result {
    case .failure(let error):
        debugPrint("Error: \(error)")
        debugPrint(response)
    case .success(let document):
        // Parsing the HTML data
        if let example = document.firstChild(css: "div > p") {
            print(example.stringValue)
        }
    }
}

请注意,如果您显式使用任何类型或类,则需要 import Alamofireimport Fuzi。 在上面的示例中,我们没有显式使用 Fuzi 定义的任何类型(例如 HTMLDocument),因此我们不必单独导入它。

完整文档在这里

许可证

AlamoFuzi 是在 MIT 许可证下发布的。 有关详细信息,请参阅 LICENSE