first of all, I'm sorry if the question is not clear. I don't exactly know how to describe my problem here.
I fetch JSON files from a website API, and i process the files with JSONDecoder. I can print the result when inside do catch
but I cant assign to either global or local variable, the debugger state variable was capture in closure before initialize
i'll edit the question once i know how to properly name the question.
func indodaxExtraction() -> apiIndodax{
let urlLink = "https://indodax.com/api/btc_idr/ticker"
let url = URL(string: urlLink)
URLSession.shared.dataTask(with: url!) { (data, response, err) in
guard let data = data else {return}
do {
let api = try JSONDecoder().decode(apiIndodax.self, from: data)
print(api.ticker.high)
print(api.ticker.low)
print(api.ticker.last)
}catch let jsonERR{
print(jsonERR)
}
}.resume()
}
I'm new in swift, just learn it for about 1 weeks. Sorry for any mistake.