329
GitHub - PromiseKit/Alamofire-: Promises for Swift & ObjC
source link: https://github.com/PromiseKit/Alamofire-
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.markdown
PromiseKit Alamofire Extensions
This project adds promises to Alamofire.
This project supports Swift 3.1, 3.2, 4.0 and 4.1.
Usage
Alamofire.request("https://httpbin.org/get", method: .GET) .responseJSON().then { json, rsp in // }.catch{ error in //… }
Of course, the whole point in promises is composability, so:
func login() -> Promise<User> { let q = DispatchQueue.global() UIApplication.shared.isNetworkActivityIndicatorVisible = true return firstly { in Alamofire.request(url, method: .get).responseData() }.map(on: q) { data, rsp in convertToUser(data) }.ensure { UIApplication.shared.isNetworkActivityIndicatorVisible = false } } firstly { login() }.done { user in //… }.catch { error in UIAlertController(/*…*/).show() }
CococaPods
# Podfile pod 'PromiseKit/Alamofire', '~> 6.0'
// `.swift` files import PromiseKit import Alamofire
// `.m files`
@import PromiseKit;
@import Alamofire;
Carthage
github "PromiseKit/Alamofire-" ~> 3.0
The extensions are built into their own framework:
// `.swift` files import PromiseKit import PMKAlamofire
// `.m files`
@import PromiseKit;
@import PMKAlamofire;
SwiftPM
let package = Package( dependencies: [ .Target(url: "https://github.com/PromiseKit/Alamofire", majorVersion: 3) ] )
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK