I have been through that tutorial. But I guess I'm not retaining knowledge that is needed. Thank you for your help.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have wrapped the (if let banjo) block in a dummy function and it builds. Only issue is where to run the function. I'd be happy with it running first in the program. As soon as I boot up. I suppose I could put a button in the content view that runs the function, which I assume would make the network call. Is that ok?
the if let banjo... line was written by you (I think). What function shouuld I enclose it in? Or do I need to make a new function that includes all we have discussed, then execute it after it's written?
if let banjo = URL(string: myString) {
let Lulah = URLSession.shared.dataTask(with:banjo ) { myDatastring , response , error in}
Lulah.resume()
} else {
myDatastring="nil url"
}
Also if you can point me to documentation that describes what the URL structure does, that might help me too. I was trying to find out why it was returning a nil value. Also what in the shared task was failing. So i was struggling to find documentation on the shared task. Again, thanks for your generous help.
I am not having trouble deciding what to do in my code if I get a non URL value in banjo. I'm using the same URL that I think I will always use, and that won't change. And that I'm checking is valid.
That being the case I've tried pasting the code you gave me into xcode and it still won't build.
Here's what I put in xcode
let myString = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=AAPL&apikey= *********"
if let banjo = URL(string: myString) {
let Lulah = URLSession.shared.dataTask(with:banjo ) { myDatastring , response , error in}
Lulah.resume()
} else {
myDatastring="nil url"
}
I'm getting a build error on the line starting "if let banjo". The build error is: "Statements are not allowed at the top level" and is tied to the first word, if.
Thank you for your generous help.
I have pasted the offending code to this forum.
The error is:Value of optional type 'URL?' must be unwrapped to a value of type 'URL'. It is tied to the line beginning "let task" and to the first mention of "banjo". Does that help?
let myString = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=AAPL&apikey= *********"
var banjo = URL(string: myString)
let task = URLSession.shared.dataTask(with:banjo ) { myDatastring , response , error in}
//task.resume()
I should also add that I have a free api key for stock info. I have used that URL, which I know works in a browser. If that helps understanding my issue there it is.
I am programming in swiftUI and I think can't do print statements like in your example.
var myString = "https://www.example.com"
var banjo = URL(string: myString)
let task = URLSession.shared.dataTask(with:banjo ) { myDatastring , response , error in}