回答編集履歴
2
参考サンプルを追記
test
CHANGED
@@ -41,3 +41,53 @@
|
|
41
41
|
|
42
42
|
|
43
43
|
```
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
追記
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
func updateImageView() {
|
54
|
+
|
55
|
+
self.fetchImage(url: URL("https://xxx.xxxx.co.jp/xxx.jpg")!, completionHanlder: { (image, error) in
|
56
|
+
|
57
|
+
/*
|
58
|
+
|
59
|
+
画像取得後の処理。
|
60
|
+
|
61
|
+
*/
|
62
|
+
|
63
|
+
});
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
func fetchImage(url: URL, completionHandler: (image: UIImage?, error: NSError?) -> Void) {
|
70
|
+
|
71
|
+
let downloader = ImageDownloader()
|
72
|
+
|
73
|
+
let urlRequest = URLRequest(url: url)
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
downloader.download(urlRequest) { response in
|
78
|
+
|
79
|
+
switch response.result {
|
80
|
+
|
81
|
+
case .Success(let image):
|
82
|
+
|
83
|
+
completionHandler(image, nil)
|
84
|
+
|
85
|
+
case .Failure(let error):
|
86
|
+
|
87
|
+
completionHandler(nil, error)
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
```
|
1
completionHandler引数の修正
test
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
```
|
14
14
|
|
15
|
-
func fetchImage(url: URL, completionHandler(image: UIImage?)) {
|
15
|
+
func fetchImage(url: URL, completionHandler: (image: UIImage?) -> Void) {
|
16
16
|
|
17
17
|
let downloader = ImageDownloader()
|
18
18
|
|