jeudi 26 décembre 2019

Reassigning a value in an if statement in Swift

the following is printing "no user with username" but is printing retVal as "false" ( I changed function to a string just for troubleshooting, ideally this should be bool ) I am new to swift and this is absolutely driving me crazy. it is making it to the chunk of code where retVal would get reassigned, but it isn't reassigning it

static func isUserNameUnique(_ username : String) -> String {

    var retVal = "false"

    let db = Firestore.firestore()
    let newQuery = db.collection("users").whereField("userName", isEqualTo: username)
    newQuery.getDocuments { (document, error) in
        if document!.isEmpty {
            retVal = "true"
            print("No user with username")

        }
    }
    print("\(retVal)")
    return retVal
}

Aucun commentaire:

Enregistrer un commentaire