【发布时间】:2019-01-01 09:47:07
【问题描述】:
今天我正在使用 Alamofire 提取一个 int 值。 它很好地提取了 int,但我想将 int 值保存在请求之外(在不同的函数中,viewDidLoad())。
我不确定如何调用完成处理程序,目前它似乎没有做任何事情。
这是提取相关 int 值的方法 (lastModified)。
func checkVersion(completion: @escaping (Int) -> Void) {
Alamofire.request(versionCheckEndpoint).responseJSON { response in
if(response.result.value != nil) {
let json = JSON(response.result.value!)
self.s3Endpoint = json["s3BucketURL"].stringValue
let lastModified = json["lastModified"].intValue
self.latestVersion = lastModified
}
}
}
我尝试将值保存到实例变量中,但这不起作用。
我在 viewDidLoad() 中调用了这样的完成处理程序。但我很肯定它远非正确:
self.checkVersion() { response in
self.latestVersion = response
}
谁能告诉我如何将 lastModified 的 int 值保存到某个局部变量,使其不包含在 Alamofire 请求的范围内?
【问题讨论】:
标签: ios swift networking alamofire completionhandler