[ad_1]
In some methods, this code labored completely as a result of it toggled on and off. Typically it really works nice, generally it crashes, and generally it really works completely. May you please inform me what went flawed with this code?
func downloadExchangeRateFromPast(toDate: Date, fromCurrency: String) {
startupCheck_ExchangeRateFromPast.enter()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let fromDate = dateFormatter.string(from: toDate)
let url = "https://api.exchangerate.host/convert?from=(currentCurrency)&to=(fromCurrency)&date=(fromDate)"
let session = URLSession(configuration: .default)
session.dataTask(with: URL(string: url)!) { (information, response, _) in
guard let JSONData = information else {
startupCheck_ExchangeRateFromPast.go away()
return
}
if let response = response as? HTTPURLResponse { print("Change Standing: (response.statusCode)") }
do {
let finalData = attempt JSONDecoder().decode(ExchangeRatePastJSON.self, from: JSONData)
let newExchangeRate = ExchangeRateConvert(context: contextDataCore)
newExchangeRate.date = toDate
newExchangeRate.fromCode = fromCurrency
newExchangeRate.toCode = currentCurrency
newExchangeRate.rateConvert = finalData.end result
let newExchangeHistoryRecord = ExchangeHistoryRecord(context: contextDataCore) // Thread 20: sign SIGABRT
newExchangeHistoryRecord.finalRecord = "(toDate) - (fromCurrency) - (currentCurrency)"
attempt contextDataCore.save()
startupCheck_ExchangeRateFromPast.go away()
} catch { startupCheck_ExchangeRateFromPast.go away() }
}
.resume()
}
[ad_2]
