Firebase iOS - Type 'LoginViewController' does not conform to protocol 'FUIAuthDelegate'

寵の児 提交于 2019-12-08 04:14:17

问题


I'm in the process of integrating the Firebase Auth UI to my app, and for some reason I keep getting this error:

Type 'LoginViewController' does not conform to protocol 'FUIAuthDelegate'

Before you start downvoting me into oblivion, I promise that I'm not an idiot. The FUIAuthDelegate only has one required function, which is listed farther down in the issue inspector:

Protocol requires function 'authUI(_:didSignInWith:error:)' with type '(FUIAuth, User?, Error?) -> Void'; do you want to add a stub?

And then this:

Candidate has non-matching type '(FUIAuth, User?, Error?) -> ()'

The thing is, I've got that function in my class, and I'm fairly certain that I'm conforming to the protocol... here's my ViewController's code:

import UIKit
import FirebaseAuth
import FirebaseAuthUI


typealias FIRUser = FirebaseAuth.User

class LoginViewController: UIViewController {

    @IBOutlet weak var loginButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func loginButtonTapped(_ sender: Any) {
        print("Login Button Tapped")

        guard let authUI = FUIAuth.defaultAuthUI()
            else { return }

        authUI.delegate = self

        let authViewController = authUI.authViewController()
        present(authViewController, animated: true)    
    }
}
extension LoginViewController: FUIAuthDelegate {
    func authUI(_ authUI: FUIAuth, didSignInWith user: User?, error: Error?) {
        print("")
    }
}

Am I insane? Can someone tell me what I'm missing here?


回答1:


Remove the FUIAuthDelegate protocol from the LoginViewController extension:

extension LoginViewController {
func authUI(_ authUI: FUIAuth, didSignInWith user: User?, error: Error?) {
    print("")
}

}

I just confirmed that when I added FUIAuthProtocol to my own app, I got the same error you saw. Without it, it runs fine.




回答2:


func authUI(_ authUI: FUIAuth, didSignInWith user: User?, error: Error?) {
    print("")
}

Replace this with

func authUI(_ authUI: FUIAuth, didSignInWith user: FirebaseAuth.User?, error: Error?) {
     print("")
}

If there is another User class defined it can cause conflict. By replacing User -> FirebaseAuth.User, we are just specifying exactly which user class should be used.



来源:https://stackoverflow.com/questions/44663741/firebase-ios-type-loginviewcontroller-does-not-conform-to-protocol-fuiauthd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!