質問するログイン新規登録

質問編集履歴

2

追加

2020/04/22 08:16

投稿

se_taro
se_taro

スコア6

title CHANGED
File without changes
body CHANGED
@@ -6,6 +6,46 @@
6
6
 
7
7
 
8
8
  ```Swift
9
+ class RegisterViewController: UIViewController, UITextFieldDelegate {
10
+
11
+ // 登録ボタン
12
+ @IBOutlet weak var Button: UIButton!
13
+ @IBOutlet weak var newname: UITextField!
14
+ @IBOutlet weak var newmail: UITextField!
15
+ @IBOutlet weak var newpass: UITextField!
16
+ @IBOutlet weak var newpass2: UITextField!
17
+
18
+ @IBAction func back_button(_ sender: Any) {
19
+ self.navigationController?.popViewController(animated: true)
20
+ }
21
+
22
+ // 登録ボタン
23
+ @IBAction func register(_ sender: Any) {
24
+
25
+ // https://teachapi.herokuapp.com/sign_up
26
+ let config: URLSessionConfiguration = URLSessionConfiguration.default
27
+
28
+ let session: URLSession = URLSession(configuration: config)
29
+
30
+ var urlComponents = URLComponents()
31
+ urlComponents.scheme = "https"
32
+ urlComponents.host = "teachapi.herokuapp.com"
33
+ urlComponents.path = "/sign_up"
34
+
35
+
36
+ let url: URL = urlComponents.url!
37
+ var req: URLRequest = URLRequest(url: url)
38
+ req.httpMethod = "POST"
39
+ req.addValue("application/json", forHTTPHeaderField: "Content-Type")
40
+ let params:[String:Any] = [
41
+ "sign_up_user_params": [
42
+ "name": "(newname.text!)",
43
+ "bio": "a",
44
+ "email": "(newmail.text!)",
45
+ "password": "(newpass.text!)",
46
+ "password_confirmation": "(newpass2.text!)"
47
+ ]
48
+ ]
9
49
  func textFieldDidEndEditing(_ textField: UITextField) {
10
50
  if newpass.text == newpass2.text {
11
51
  do{

1

誤字

2020/04/22 08:16

投稿

se_taro
se_taro

スコア6

title CHANGED
File without changes
body CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  print(req)
18
18
  let task = session.dataTask(with: req) { (data, response, error) in
19
- // tokenせーぶしてるコード。これを登録とかログインに書くとどこでもtoken使えるようになる
19
+
20
20
  do {
21
21
  let json: [String: Any] = try JSONSerialization.jsonObject(with: data!, options: []) as! [String: Any]
22
22
  UserDefaults.standard.set(json["token"], forKey: "token")