官术网_书友最值得收藏!

Making your first call with URLSession

Let's take a look at the anatomy of a simple URL task:

let url = URL(string: "https://api.website.com/")!
let task = URLSession.shared.dataTask(url: url) { data, response, error in
if let error = error { return } // handle the error somehow
guard let response = response as HTTPURLResponse,
let data = data else { return }
// data: Data is set, and all good
}
task.resume()

If the call has succeeded, the data variable will be set and will contain the data downloaded from the remote server.

主站蜘蛛池模板: 靖远县| 贵定县| 永泰县| 北海市| 苏尼特右旗| 江永县| 齐齐哈尔市| 潞城市| 宣威市| 永定县| 丹阳市| 象州县| 海安县| 江安县| 龙胜| 桐乡市| 达孜县| 内丘县| 株洲县| 开江县| 固阳县| 兴业县| 贵定县| 中江县| 新营市| 香港| 旅游| 成都市| 雅江县| 灵川县| 沂源县| 分宜县| 溧阳市| 乌拉特前旗| 兴隆县| 大新县| 巨野县| 南昌县| 海林市| 舒城县| 嘉兴市|