I am running Xcode 10.3 on a MBP from 2015. Does this limit the version of Swift I can write with? How can I tell which version of Swift I am using?
I am getting an error: Value of type URL has no member 'withQueries' and I think it is because the code is incompatible with the version of Swift I am using?
let baseURL = URL(string: "https://api.nasa.gov/planetary/apod")!
let query: [String: String] = [
"api_key": "DEMO_KEY",
"date": "2011-07-13"]
let url = baseURL.withQueries(query)!
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
if let data = data,
let string = String(data: data, encoding: .utf8) {
print(string)
}
PlaygroundPage.current.finishExecution()
}
task.resume()
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I am working my way through a Swift course from 2015. It is asking me to "Write a function called magicEightBall that generates a random number and then uses either a switch statement or if-else-if statements to print different responses based on the random number generated. let randomNum = Int.random(in: 0...4) will generate a random number from 0 to 4, after which you can print different phrases corresponding to the number generated. Call the function multiple times and observe the different printouts."
Here is what I have written so far, but it isn't working:
func magicEightBall(randomNum: Int) {
let randomNum = Int.random(in: 0...4)
print(randomNum)
}
magicEightBall()
I keep getting an error that says "Missing argument for parameter 'randomNum' in call
any help would be greatly appreciated, Thank You