swift
1import UIKit 2import Firebase 3import FirebaseAuth 4 5class SignUpViewController: UIViewController { 6 7 var email:UITextField! 8 var password:UITextField! 9 var signin:UIButton! 10 var create:UIButton! 11 let BTN_SIGN = 0 12 let BTN_C = 1 13 14 15 16 override func viewDidLoad() { 17 super.viewDidLoad() 18 // Do any additional setup after loading the view, typically from a nib. 19 20 let x = (UIScreen.main.bounds.size.width-200)/2 21 let y = (UIScreen.main.bounds.size.height+80)/9 22 23 email=makeTextField(frame: CGRect(x:x, y:y,width: 200,height: 30), text: "") 24 self.view.addSubview(email) 25 26 password=makeTextField(frame: CGRect(x: x,y: y+40,width: 200,height: 30), text: "") 27 password.isSecureTextEntry = true 28 self.view.addSubview(password) 29 30 31 signin=makeButton(frame: CGRect(x:x, y:y+80,width: 60, height:30), text: "signin", tag: BTN_SIGN) 32 signin.addTarget(self, action:#selector(SignUpViewController.onClick(sender:)), for: .touchUpInside) 33 self.view.addSubview(signin) 34 35 create=makeButton(frame: CGRect(x:x+100,y:y+80, width:60,height: 30), text: "create", tag: BTN_C) 36 create.addTarget(self, action: #selector(SignUpViewController.onClick(sender:)), for: .touchUpInside) 37 self.view.addSubview(create) 38 39 } 40 41 func onClick (sender:UIButton){ 42 if sender.tag == BTN_SIGN { 43 44 45 FIRAuth.auth()?.signInWithEmail(email.text!, password: password.text!, completion: { user, error in 46 if let error = error { 47 print("サインインできません \(error)") 48 return 49 } 50 51 if let user = user { 52 print("user : \(user.email!) サインインできました") 53 } 54 }) 55 56 57 }else if sender.tag == BTN_C { 58 59 FIRAuth.auth()?.createUserWithEmail(email.text!, password: password.text!, completion: { user, error in 60 if let error = error { 61 print("ユーザーを作れませんでした \(error)") 62 return 63 } 64 65 if let user = user { 66 print("user : \(user.email!)ユーザーを作成しました") 67 } 68 }) 69 70 } 71 72 } 73 74 75 func makeTextField(frame:CGRect,text:String)->UITextField{ 76 let textField = UITextField() 77 textField.frame = frame 78 textField.text = text 79 textField.backgroundColor = UIColor.white 80 textField.layer.cornerRadius = 8 81 textField.clearButtonMode = UITextFieldViewMode.whileEditing 82 83 return textField 84 } 85 86 func makeButton(frame:CGRect,text:String,tag:Int)->UIButton { 87 let button = UIButton(type:UIButtonType.system) 88 button.frame = frame 89 button.setTitle(text , for: UIControlState.normal) 90 button.tag = tag 91 return button 92 } 93 94 95 override func didReceiveMemoryWarning() { 96 super.didReceiveMemoryWarning() 97 // Dispose of any resources that can be recreated. 98 } 99 100 101} 102
以上のコードでメールアドレスとパスワードを登録してfirebaseで認証しようと考えています。
しかし、import FirebaseAuthのところでno such module 'FirebaseAuth'というエラーが発生していましました。
このimport FirebaseAuthをやらないとuse of unresolved identifier FIRAuthというエラーが発生します。どうすればエラーを解除できるのでしょうか教えてください。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。