I have been using Youtube to help me with learning how to use API and converting to JSON using SwiftUI. This is my first time actually using it and could use help, if possible please… this Is what my code is showing: "can not find error in scope"
This is the code so far:
import SwiftUI
class ViewModel: ObservableObject{
func fetch() {
guard let url = URL(string: "http://www.themealdb.com/api/json/v1/1/search.php?s=Arrabiata") else {
return
}
}
let task = URLSession.shared.dataTask(with: url) { data;
error; in
guard let data = data, error == nil else {
return
}
// Convert to JSON
}
}
I am so sorry, I am still very new to this all.
Thank you!
I have tried using Youtube for help.
2
Answers
There are two (actually three) serious mistakes.
let task
is wrong, it must be at the end.dataTask
has three parameters separated by commaAnd it’s good practice to handle/print the
error
. If there is no errordata
has a value and can be forced unwrapped.Side note:
Rather than YouTube where anybody can publish anything read/watch serious tutorials like Hacking With Swift.
This may help you.