Swift Sample
ナビゲーションに移動
検索に移動
Swift Sample
Network
データ取得
let url = URL(string: "https://www.typea.info/blog/")! let task = URLSession.shared.dataTask(with: url) { data, response, error in if let error = error { print("\(error)\n") return } guard let data = data, let response = response as? HTTPURLResponse else { print("no data or no response.") return } if response.statusCode == 200 { if let text = String(bytes: data, encoding: .utf8) { print(text) } } } task.resume()
MacOSでエラーの場合
Error Domain=NSURLErrorDomain Code=-1003
*https://www.poly-rhythm.com/hostname-could-not-be-found/ *https://developer.apple.com/documentation/xcode/adding_capabilities_to_your_app
© 2006 矢木浩人