localizedDescription Not available

Following Chris’s tutorial on “Firebase Authentication Tutorial 2020 - Custom iOS Login Page (Swift)”, for errorLabel output I didn’t get .localizedDescription method being auto prompted or even available in the list. There are other .localized methods appearing. Any suggestions to fix. BTW, I’m running Xcode 12.4

Hi @srikalvan

It will help if you post your code for the method so that we can see the context in which you are having trouble.

@IBAction func loginButtonTap(_ sender: Any) {
// Validate the fields
let error = validateFields()

    if error != nil {
        // There is something wrong with the field entry, display message
        self.showError(error!)
    }
    else {
        // Create cleaned versions of the data
        let email = userNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
        let password = passwordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
        
        // Sign In the user
         Auth.auth().signIn(withEmail: email, password: password) { (result, err) in
            if err != nil {
                //self.errorLabel.text = error!.localizedDescription
                self.errorLabel.text = error!.localizedDescription
                self.errorLabel.alpha = 1
            }
            else {
                // Go to home screen on successful login
                self.transitionToHome()
            }
         }
    }

That’s odd. I have the same code in my version.

Try closing the project, restart Xcode, reopen the project, clean the build folder (Shift + Command + K) and then see of that autocomplete works again.

I’ll try and share the results. Another weird thing I notice on the Xcode dashboard is that 2 Santevalue… projects are seen one with an icon that is pale blue while the other is dark blue…

When you add Cocoapods to a project you then open the project from the file named YourProjectName.xcworkspace rather than YourProjectName.xcodeproj

The pale blue ones are projects which have been opened via the .xcorkspace filename extension.

Thanks Chris. Cleaning with Shift+Command K also didn’t work to fix the localizedDescription issue. Now rubbing salt to the exposed wound, I get an error for Import Firebase…this despite having the Firebase folders available on Pods…

Build the project again. Commnd + B.

Thanks. Running build helped with the Firebase error…loclaizedDescription error persists

I think I can now see the problem in your original code segment you posted earlier.

The issue is related to naming your parameters in the Auth.auth sign in function. You have the two parameters (result, err) and you refer to err in your if statement like this:
if err != nil {

but then when you are assigning your error details to your label you have this:
self.errorLabel.text = error!.localizedDescription

whereas you should be referring to the err you defined earlier. So if you had this:
self.errorLabel.text = err!.localizedDescription

you will find that it should work.

A point to note:
When following along with a tutorial it is best to use exactly the same variable names as the tutorial shows rather than shortening them or changing them for whatever the reason. In this case it has caused you some grief.
The Auth.auth parameters result and error are known only to the Auth.auth closure. The error outside of that closure further up in your code is not known to it so they are two completely different variables in terms of what is known as “scope of variables”.

It would be better for your code to have used the name error rather than err so that the Auth.auth code segment would look like this:

Auth.auth().signIn(withEmail: email, password: password) { (result, error) in
    if error != nil {
        self.errorLabel.text = error.localizedDescription
        self.errorLabel.alpha = 1
    }
    else {
        // Go to home screen on successful login
        self.transitionToHome()
    }
}

The other thing I noticed in your code is that you are validating the email and password fields initially via the code:
let error = validateFields()

That being the case and assuming that your validateFields() function looks like this:

    func validateFields() -> String? {
        email = emailTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
        password = passwordTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
        
        //  Check that all fields are filled in
        if email == "" || password == "" {
            showError("Email and Password must be supplied")
        }
        return nil
    }

Then cleaning them again a little further down is not necessary.

Hope this helps.

Yes it worked! Thank you very much for the help. You have been wonderful. This was a great learning experience. I’ll keep you informed of the progress. I really enjoy your course and wish you to keep teaching us. Thanks again

They are not my courses. The man who creates all these courses is Chris Ching. Same first name only. I’m one of the moderators on the site.

Great to hear that it is working.