AlamofireSync
AlamofireSync
是一个 Swift 扩展,允许对 Alamofire 进行同步请求。
要求
- iOS 10.0 或更高版本
- macOS 10.12 或更高版本
- tvOS 10.0 或更高版本
- watchOS 3.0 或更高版本
- Swift 5
安装
Carthage
在您的 Cartfile
中添加以下内容,并按照这些说明操作。
github "gumob/AlamofireSync"
CocoaPods
要将AlamofireSync集成到您的项目中,请将以下内容添加到您的Podfile
中。
pod 'AlamofireSync'
用法
有关更多信息,请参阅AlamofireSyncTests.swift。
使用Alamofire.DataRequest
let response = AF.request("https://httpbin.org/image/jpeg")
.response()
if let data = response.data {
let image = UIImage(data: data)
}
使用Alamofire.DownloadRequest
let destination: DownloadRequest.Destination = { _, _ in
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let fileURL = documentsURL.appendingPathComponent("response.json")
return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
}
let response = AF.download("https://httpbin.org/get", method: .get, parameters: ["foo": "bar"], to: destination)
.downloadProgress { progress in
print("Download Progress: \(progress.fractionCompleted)")
}.responseJSON()
版权
AlamofireSync采用MIT许可发布,这意味着您可以修改、重新分发或以任何您喜欢的方式使用它。