It logged something like this " nw_protocol_get_quic_image_block_invoke dlopen libquic failed " but there's a value in it.
When I tried to print it out in a view, it does not work at all What did I do wrong?
class MoneyView:ObservableObject {
@Published var currency:Rate?
init() {
fetchData()
print(self.currency!.CAD) // This does not have any value aka nil
}
func fetchData() {
print("Gajellas amat")
guard let url = URL(string: "http://api.exchangeratesapi.io/v1/latest?access_key=24a5ab7688a7044f60bfeb491eb37550") else {
return
}
let session = URLSession(configuration: .default)
let task = session.dataTask(with: url) {(data, response, error) in
if error == nil {
let decoder = JSONDecoder()
if let safeData = data {
do{
let result = try decoder.decode(Root.self, from: safeData)
DispatchQueue.main.async {
self.currency = result.rates
print(result.rates.CAD)
print("Ada ada aja -----------")
print(self.currency!.CAD) // This has value
}
} catch {
print(error)
}
}
}
}
task.resume()
}
}
my view :
struct NewDisplay: View {
@ObservedObject var fetch = MoneyView()
var body: some View {
Text(String(self.fetch.currency!.CAD))
Text("Makan bang")
}
}