A new Swift guy here. I'm trying to figure out how to chain multiple Alamofire calls together.
I need to
- get an auth token from Server 1
- get some data from Server 1 (need the auth token)
- get an auth token from Server 2
- Get more data from Server 2 based on the values from step 2.
I've tried following the examples on this post: Chain multiple Alamofire requests
Unfortunately none of those examples are working with Swift 4.
I've decided to pursue Option 2, but keep getting a
Cannot call value of non-function type '
HTTPURLResponse?
'
error both on the putRequest
and getRequest
lines. I have no idea what that means or how to fix it.
My current code:
import UIKit
import PromiseKit
import Alamofire
import SwiftyJSON
class ViewController: UIViewController {
let URL = "http://httpbin.org/"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func runPutRequest() {
let putRequest = Alamofire.request("\(URL)/get")
putRequest.response { [weak self] putRequest, putResponse, putData, putError in
if let strongSelf = self {
// Probably store some data
strongSelf.runGetRequest()
}
}
}
func runGetRequest() {
let getRequest = Alamofire.request("\(URL)/get", method: .get)
getRequest.response { [weak self] getRequest, getResponse, getData, getError in
if let strongSelf = self {
// Probably store more data
strongSelf.processResponse()
}
}
}
func processResponse() {
// Process that data
}
func reloadData() {
// Reload that data
}
}
Any help would be greatly appreciated.