如何为一个可以在块中可修改的类赋值?

时间:2018-05-15 03:38:55

标签: swift

我正在尝试从块内部为类变量设置一个值。但由于某种原因,价值没有设定。坦率地说,我真的不知道如何从块内部为类变量设置值,所以任何帮助都会受到赞赏。

这是我的代码:

class PhoneAuthViewController: UIViewController {
var verificationID: String = ""

@IBAction func activateButtonPressed(_ sender: UIButton) {
        var phoneNumberString = ""
        if phoneNumberField.text != nil {
            phoneNumberString = phoneNumberField.text!
        } else {
            phoneNumberString = ""
        }
        //Checking if the phone number is in the right format
        let phoneNumberFormatStatus = checkPhoneNumberFormat(phoneNumberData: phoneNumberString)
        if (phoneNumberFormatStatus != true) {
            //Showing the alert if the user enters invalid phone number
            showInvalidPhoneNumberAlert(phoneNumberData: phoneNumberString)
        }
        verifyPhoneWithFireBase(phoneNumberData: phoneNumberString)
    }


func verifyPhoneWithFireBase(phoneNumberData: String) {
    PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumberData, uiDelegate: nil) { (verificationID, error) in
        if (verificationID != nil) {
            self.verificationID = verificationID!
        }
        if let error = error {
            self.showAlert(errorString: error.localizedDescription)
            return
        } else {
            self.performSegue(withIdentifier: "otpVerificationScreen", sender: self.activateButton)
        }
    }
}
@IBAction func verifyOtp(_ sender: UIButton) {
        print("\(self.verificationID) is self.verificationID")
        print("\(verificationID) is verificationID")
    }
   }

函数verifyOtp不会打印任何内容。

0 个答案:

没有答案