回答編集履歴

2

s

2018/06/07 20:10

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -15,3 +15,35 @@
15
15
 
16
16
 
17
17
  非同期にしても、取得できてから遷移すれば問題ないと思いますよ。
18
+
19
+
20
+
21
+ ```swift
22
+
23
+
24
+
25
+ @IBAction func buttonPressed(_ sender: Any) {
26
+
27
+ guard let searchWord = searchField.text else { return }
28
+
29
+ Alamofire.request("https://api.github.com/search/repositories?q=(searchWord)&page=1").responseJSON(queue: queue) { (response) in
30
+
31
+ guard response.result.isSuccess else { return }
32
+
33
+ guard let object = response.result.value as? [String:Any] else {return}
34
+
35
+ let result = Result(object: object)
36
+
37
+ self.repositories = result.items
38
+
39
+
40
+
41
+ // 通信終了後画面遷移
42
+
43
+ performSegue()
44
+
45
+ }
46
+
47
+ }
48
+
49
+ ```

1

s

2018/06/07 20:10

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -7,3 +7,11 @@
7
7
 
8
8
 
9
9
  それでなければ、前画面でAPI実行して取得できたら、データを渡して画面遷移のどちらかでしょう。
10
+
11
+
12
+
13
+ > 非同期にすると、repositoriesが渡される前に画面遷移されるので次の画面でコンテンツを表示たいのにnilになってしまう。
14
+
15
+
16
+
17
+ 非同期にしても、取得できてから遷移すれば問題ないと思いますよ。