回答編集履歴

2

修正

2016/10/16 14:18

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -1,4 +1,16 @@
1
1
  引数の型が違うようですね、以下の様にすることで取得できると思います、試してみてください。
2
+
3
+
4
+
5
+ ```swift
6
+
7
+ open func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Swift.Void) -> URLSessionDataTask
8
+
9
+ ```
10
+
11
+
12
+
13
+ `URL` → `URLRequest`
2
14
 
3
15
 
4
16
 

1

修正

2016/10/16 14:18

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -1,4 +1,4 @@
1
- 以下の様にすることで取得できると思います、試してみてください。
1
+ 引数の型が違うようですね、以下の様にすることで取得できると思います、試してみてください。
2
2
 
3
3
 
4
4
 
@@ -18,9 +18,9 @@
18
18
 
19
19
 
20
20
 
21
- let url = NSURL(string: "http://www.weather-forecast.com/locations/Tokyo-1/forecasts/latest")
21
+ let url: URL = URL(string: "http://www.weather-forecast.com/locations/Tokyo-1/forecasts/latest")!
22
22
 
23
- let task = URLSession.shared.dataTask(with: URLRequest(url: url as! URL)) { data, response, error in
23
+ let task = URLSession.shared.dataTask(with: URLRequest(url: url), completionHandler: { (data, response, error) in
24
24
 
25
25
  if error != nil {
26
26
 
@@ -28,23 +28,17 @@
28
28
 
29
29
  print(error!.localizedDescription)
30
30
 
31
-
32
-
33
31
  } else {
34
32
 
35
33
 
36
34
 
37
- if let _ = response, let data = data {
38
-
39
-
40
-
41
- print(NSString(data: data, encoding: String.Encoding.utf8.rawValue))
35
+ print(NSString(data: data!, encoding: String.Encoding.utf8.rawValue))
42
-
43
- }
44
36
 
45
37
  }
46
38
 
39
+
40
+
47
- }
41
+ })
48
42
 
49
43
  task.resume()
50
44