swiftxcodescopefuncguard

Swift unabel to find "" in scope


So I'm trying to create an app with a login and register screen and I've created a guard function to create and add a new account in which i could log in later.

Thi is the implementation

import FirebaseFirestore
import FirebaseAuth
import Foundation

class RegisterViewViewModel: ObservableObject{
    @Published var name = ""
    @Published var email = ""
    @Published var password = ""
    
    init(){}
    
    func register(){
        guard validate() else{
            return
        }
        Auth.auth().createUser(withEmail: email, password: password) { [weak self] result, error in
            guard let userId = result?.user.uid else{
                return
            }
            self?.insertUserRecord(id: userId)
        }
    }
    
    private func insertUserRecord(id: String){
        let newUser =  User(id: id,
                            name: name,
                            email: email,
                            joined: Date().timeIntervalSince1970)
        
        let db = Firestore.firestore()
        
        db.collection("users")
            .document(id)
            .setData(newUser.asDictionary())
    }
    
    private func valdiate() -> Bool{
        guard !name.trimmingCharacters(in: .whitespaces).isEmpty,
              !email.trimmingCharacters(in: .whitespaces).isEmpty,
              !password.trimmingCharacters(in: .whitespaces).isEmpty else{
            return false
        }
        guard email.contains("@")&&email.contains(".")else{
             return false
        }
        guard password.count>=6 else {
            return false
        }
        return true
    }
}

The eror is at "guard validate()" and it says "Cannot find validate in scope"


Solution

  • You have a typo in your function declaration:

        private func valdiate() -> Bool{
    

    should be:

        private func validate() -> Bool{