Firebase iOS - Type 'LoginViewController'

2019-06-05 12:47发布

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?

2条回答
走好不送
2楼-- · 2019-06-05 13:19

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.

查看更多
Fickle 薄情
3楼-- · 2019-06-05 13:23
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.

查看更多
登录 后发表回答