我的问题是如何防止此崩溃?
Crash report 我在应用商店上的实时应用发生崩溃,可以在管理器->崩溃:应用商店>发布中看到 单击以将其引导至该功能
fetchClientBalance() { (result, error) in
let (hour,min,secs) = secondsToHoursMinutesSeconds(seconds: Int(durationInSecs)) // Crash here
}
功能的实现是
func secondsToHoursMinutesSeconds (seconds : Int) -> (Int, Int, Int) {
return (seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60)
}
func fetchClientBalance(completed: @escaping ((_ result: Balance?, _ error: Error?) -> Void)) {
URLSession.shared.dataTask(with: url) { (data, response, error) in
if error != nil {
print("Error in fetching balance")
print(error!.localizedDescription)
completed(nil,error)
return
}
guard let data = data else {
print(error?.localizedDescription ?? "No data")
completed(nil,error)
return
}
do {
let resultData = try JSONDecoder().decode(Balance.self, from: data)
DispatchQueue.main.async {
completed(resultData,nil)
return
}
} catch let jsonError {
print("JSON Decoding Error")
print(jsonError)
completed(nil,jsonError)
return
}
}.resume()
}