我正在使用alamofire进行服务集成 . 它有时只给[]一个空的响应 . 在那个时候应用程序因为空数组响应而崩溃 . 如何在swift iOS中处理该响应 .
这是我的代码:
let headers = ["Authorization" : "Bearer "+token,
"Content-Type": "application/json"]
Alamofire.request(“http://sos.partnersbuddy.in/api/friend_request/received ", method: .get, encoding: JSONEncoding.default, headers: headers).responseJSON { response in // print(" Request(response.request)”)
print("RESPONSE \(String(describing: response.result.value))")
print("RESPONSE \(response.result)")
print("RESPONSE \(response)")
var respVO:[RequestResvo] = Mapper().mapArray(JSONArray: response.result.value as! [[String : Any]])
print(respVO)
self.postID = respVO[0].id!
if let result = response.result.value {
let JSON = result as! NSArray
print(JSON.value(forKey: "user"))
let res = JSON.value(forKey: "user")
let respVo = Mapper().mapArray(JSONArray: res as! [[String : Any]])
for (index, element) in (respVo.enumerated()) {
print(index)
self.nameArr.append(element.first_name!)
self.numberArr.append(element.mobile!)
print("nameArr\(self.nameArr)")
print("numberArr\(self.numberArr)")
DispatchQueue.main.async {
// update your UI and model objects here
self.mytableView.reloadData()
// SKActivityIndicator.dismiss()
}
}
}
}
如何在该时间应用中处理此空响应由于空数组响应而崩溃 . 如何在swift iOS中处理该响应 .