Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

swift - How can i access firebase variable outside firebase function

Im trying to update a variable inside a class "var CurrentStatus:status! " status is an enum. I have a firebase function that will update the variable. the variable get update inside the firebase function but it will not update the variable outside of the firebase function

class signUpClass:UIViewController {

    // check to see if form is empty

    let ihelpController = UIViewController()
    var CurrentStatus:status!

    func signUp(var formArray: [String:String]) -> status{

        var formStatus:status = ihelpController.checkIfFormIsEmpty(formArray)

        if (formStatus == status.success){
          //form is ok to process
          // check DOB
          //TODO: create date calculation function

            let DateOfBirth:Int = 18

            if DateOfBirth < 18 {
               //user is not 18 they can not register
                alertError("oops", message: "You must be 18 to register", comfirm: "Ok")

            } else {
                //Proceed with registration
                let firebaseController = Firebase()
                var email = "asdf@afd.com"
                var password = "1234"

                firebaseController.refPath("users").createUser(email, password: password, withValueCompletionBlock: {error, result in

                    if error != nil {
                        print("registration Error")
                      self.alertError("oops", message: "That email is registered already", comfirm: "OK")

                    } else {
                        let vc =
                        print("user can register")
                        firebaseController.firebaseRefUrl().authUser(email, password: password, withCompletionBlock:{
                            error, authdata in

                            if error != nil {

                                print("login Error")
                            }else{

                                let userId = firebaseController.firebaseRefUrl().authData.uid

                                formArray["userId"] = userId

                                firebaseController.refPath("users/(userId)").updateChildValues(formArray)
                                print("user is register and can proceed to dashBoard")

                                //Proceed to dashboard
                                self.CurrentStatus = status.success
                            }

                        })

                    }
                })

            }




        }
       return CurrentStatus

    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...