- Hands-On Design Patterns with Swift
- Florent Vilmart Giordano Scalzo Sergio De Simone
- 92字
- 2021-07-02 14:45:12
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.
推薦閱讀
- 數據浪潮
- 大數據技術基礎
- 企業數字化創新引擎:企業級PaaS平臺HZERO
- Voice Application Development for Android
- 文本數據挖掘:基于R語言
- 云計算服務保障體系
- 數據庫系統原理及應用教程(第4版)
- Sybase數據庫在UNIX、Windows上的實施和管理
- 大數據治理與安全:從理論到開源實踐
- PostgreSQL指南:內幕探索
- IPython Interactive Computing and Visualization Cookbook(Second Edition)
- MySQL數據庫應用與管理
- 數據中臺實戰:手把手教你搭建數據中臺
- Oracle 內核技術揭密
- 數據會說話:活用數據表達、說服與決策