Can't get a simple network call working. Novice developer.

Here is my code and the error code being generated during build.

let myString : String = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=AAPL&apikey= D5GY7HKODE66G0T9" var banjo = URL(string: myString) let task = URLSession.shared.dataTask(with:banjo ) { myDatastring , response , error in} // task.resume()

I've tested that URL in my browser and it works. But when I try to build I get: Value of optional type 'URL?' must be unwrapped to a value of type 'URL'

Please tell me what I'm doing wrong. I think the URL struct is not returning a URL type of object.

init?(string: String) returns an optional value.

guard let url = URL(string: "https://...") else { return }
let request = URLRequest(url: url)
URLSession.shared.dataTask(with: request)

or

guard let url = URL(string: "https://...") else { return }
do {
    let (data, _) = try await URLSession.shared.data(from: url)
} catch {
    
}

@BillAlvord Not sure you really meant to put your actual private API key in your post... You might want to have that one destroyed and get another so others browsing these forums don't use it.

Can't get a simple network call working. Novice developer.
 
 
Q