質問編集履歴
2
APIの処理を追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,6 +30,68 @@
|
|
30
30
|
|
31
31
|
testText.text = "" // ここでエラー発生
|
32
32
|
|
33
|
+
|
34
|
+
|
35
|
+
let apiURL = URL(string:"https://testapi.com")!
|
36
|
+
|
37
|
+
var request = URLRequest(url: apiURL)
|
38
|
+
|
39
|
+
request.httpMethod = "POST"
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
// APIに接続
|
44
|
+
|
45
|
+
URLSession.shared.dataTask(with: request) {data, response, err in
|
46
|
+
|
47
|
+
if (err == nil) {
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
// 通信成功
|
52
|
+
|
53
|
+
do {
|
54
|
+
|
55
|
+
// メインメニューに遷移
|
56
|
+
|
57
|
+
let storyboard: UIStoryboard = self.storyboard!
|
58
|
+
|
59
|
+
let nextView = storyboard.instantiateViewController(withIdentifier: "MainView") as! MainViewController
|
60
|
+
|
61
|
+
self.present(nextView, animated: false, completion: nil)
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
} catch {
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
// 通信エラー
|
70
|
+
|
71
|
+
let alert = UIAlertController(
|
72
|
+
|
73
|
+
title: "エラー",
|
74
|
+
|
75
|
+
message: "通信エラー",
|
76
|
+
|
77
|
+
preferredStyle: .alert)
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
alert.addAction(UIAlertAction(title: "OK", style: .default))
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
self.present(alert, animated: true, completion: nil)
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
}.resume()
|
94
|
+
|
33
95
|
}
|
34
96
|
|
35
97
|
```
|
1
@IBAction var func loginButton\(_ sender: Any\) { の「var」を削除しました。転記ミスです。
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
-
@IBAction func
|
29
|
+
@IBAction func loginButton(_ sender: Any) {
|
30
30
|
|
31
31
|
testText.text = "" // ここでエラー発生
|
32
32
|
|