前提
ログイン機能付きの画面を作っています。
https://youtu.be/KEvA0sSpOMo
上記の動画を見ながら作っている初心者です。
FirebaseAuthの導入部分です。
環境
MacBook Air
xcode14
swift storyboard
実現したいこと
Cannot find 'Auth' in scopeを直したい
発生している問題・エラーメッセージ
Cannot find 'Auth' in scope
該当のソースコード
swift
1import UIKit 2import Firebase 3import FirebaseAnalytics 4 5class ViewController: UIViewController { 6 7 @IBOutlet weak var registerbuttom: UIButton! 8 @IBOutlet weak var emailTextField: UITextField! 9 @IBOutlet weak var passwordTextField: UITextField! 10 @IBOutlet weak var usernameTextField: UITextField! 11 12 @IBAction func renegisterbutton(_ sender: Any) { 13 handleAuthToFirebase() 14 print("renegisterbuttom") 15 } 16 private func handleAuthToFirebase() { 17 guard let email = emailTextField.text 18 guard let password = passwordTextField.text 19 20 Auth.auth().createUser(withEmail: email, password: password) { (res,err) in 21 if let err = err { 22 print("認証に失敗しました") 23 } 24 } 25 26 } 27 28 override func viewDidLoad() { 29 super.viewDidLoad() 30 31 registerbuttom.isEnabled = false 32 registerbuttom.layer.cornerRadius = 10 33 registerbuttom.backgroundColor = UIColor.rgb(red: 225, green: 221, blue: 187) 34 35 emailTextField.delegate = self 36 passwordTextField.delegate = self 37 usernameTextField.delegate = self 38 39 NotificationCenter.default.addObserver(self, selector: #selector(showKeyboard), name: UIResponder.keyboardWillShowNotification, object: nil) 40 NotificationCenter.default.addObserver(self, selector: #selector(hideKeyboard), name: UIResponder.keyboardWillHideNotification, object: nil) 41 42 } 43 44 @objc func showKeyboard(notification: Notification) { 45 let keyboardFrame = (notification.userInfo![UIResponder.keyboardFrameEndUserInfoKey] as AnyObject).cgRectValue 46 47 guard let keyboardMinY = keyboardFrame?.minY else { return } 48 let registerButtomMaxY = registerbuttom.frame.maxY 49 let deistance = registerButtomMaxY - keyboardMinY + 20 50 51 let transform = CGAffineTransform(translationX: 0, y: -deistance) 52 53 UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [], animations: { 54 self.view.transform = transform 55 }) 56 57 //print("keyboardMinY : ", keyboardMinY, "registerButtomMaxY: ", registerButtomMaxY) 58 } 59 60 @objc func hideKeyboard() { 61 UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [], animations: { 62 self.view.transform = .identity 63 }) 64 } 65 66 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 67 self.view.endEditing(true) 68 } 69} 70 71extension ViewController: UITextFieldDelegate { 72 73 func textFieldDidChangeSelection(_ textField: UITextField) { 74 let emailIsEmpty = emailTextField.text?.isEmpty ?? true 75 let passwordIsEmpty = passwordTextField.text?.isEmpty ?? true 76 let usernameIsEmpty = usernameTextField.text?.isEmpty ?? true 77 78 if emailIsEmpty || passwordIsEmpty || usernameIsEmpty { 79 registerbuttom.isEnabled = false 80 registerbuttom.backgroundColor = UIColor.rgb(red: 225, green: 221, blue: 187) 81 } else { 82 registerbuttom.isEnabled = true 83 registerbuttom.backgroundColor = UIColor.rgb(red: 225, green: 141, blue: 0) 84 } 85 86 87 } 88}
回答1件
あなたの回答
tips
プレビュー