AlamofireSync
AlamofireSync
is a Swift extension that allows synchronous requests for Alamofire.
Requirements
- iOS 10.0 or later
- macOS 10.12 or later
- tvOS 10.0 or later
- watchOS 3.0 or later
- Swift 5
Installation
Carthage
Add the following to your Cartfile
and follow these instructions.
github "gumob/AlamofireSync"
CocoaPods
To integrate AlamofireSync into your project, add the following to your Podfile
.
pod 'AlamofireSync'
Usage
See AlamofireSyncTests.swift for more usage.
Using Alamofire.DataRequest
let response = AF.request("https://httpbin.org/image/jpeg")
.response()
if let data = response.data {
let image = UIImage(data: data)
}
Using 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()
Copyright
AlamofireSync is released under MIT license, which means you can modify it, redistribute it or use it however you like.