API Basic To Advance in 9 Steps. Become Pro.
API Basic To Advance in 9 Steps. Code Like Pro. 1. Basic API Call A simple GET request using URLSession . import Foundation func basicGetRequest () { guard let url = URL (string: "https://jsonplaceholder.typicode.com/todos/1" ) else { return } let task = URLSession .shared.dataTask(with: url) { (data, response, error) in guard let data = data, error == nil else { print ( "Error:" , error ?? "Unknown error" ) return } if let httpResponse = response as? HTTPURLResponse { print ( "Status Code: \(httpResponse.statusCode) " ) } if let result = try? JSONSerialization .jsonObject(with: data, options: []) { print ( "Result:" , result) } } task.resume() } 2. Handling JSON with Decodable Use Codable for type-safe JSON parsing. import Foundation struct Todo : Codable { let userId:...