Answers for "url request in swift"

0

swift url request

import Foundation

let apiUrl = URL(string: "https://api.chucknorris.io/jokes/random")!
let dataTask = URLSession.shared.dataTask(with: apiUrl) { (data, response, error) in
    guard let data = data, error == nil else {
        print("no data")
    }
    let jsonResult = try! JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
    print(jsonResult["value"])
}
dataTask.resume()
Posted by: Guest on May-22-2021

Code answers related to "Swift"

Browse Popular Code Answers by Language