I have a struct that I am using to call out to the iTunes API. But when ever I run it myURL
variable is never getting set, it's always nil
. Not sure what I am doing wrong:
let myDefaultSession = URLSession(configuration: .default) var myURL: URL? var myDataTask: URLSessionTask? struct APIManager { func getJSON(strURL: String) { myURL = URL(string: strURL) var dictReturn: Dictionary<String, Any> = [:] //cancel data task if it is running myDataTask?.cancel() print(myURL!) //<----Always nil } }
Here's the string:
"https://itunes.apple.com/search?media=music&entity=song&term=The Chain"