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
© 2006 矢木浩人