Ios 代码永远不会被错误执行

Ios 代码永远不会被错误执行,ios,objective-c,firebase,firebase-authentication,Ios,Objective C,Firebase,Firebase Authentication,Xcode显示了代码永远不会被执行的警告,但是我不明白为什么。谁能启发我?(该错误发生在两条验证语句的完成处理程序内部的内部if和else语句中) } 编辑: - (IBAction)siginButtonPressed:(UIButton *)sender { if (isLogin) { [[FIRAuth auth] signInWithEmail:_usernameTextField.text password:_passwo

Xcode显示了代码永远不会被执行的警告,但是我不明白为什么。谁能启发我?(该错误发生在两条验证语句的完成处理程序内部的内部if和else语句中)

}

编辑:

- (IBAction)siginButtonPressed:(UIButton *)sender
{
if (isLogin)
{
    [[FIRAuth auth] signInWithEmail:_usernameTextField.text
                           password:_passwordTextField.text
                         completion:^(FIRUser *user, NSError *error)
                         {
                             if (error.code == FIRAuthErrorCodeUserNotFound)
                             {
                                 _credentialVerification.text = @"Invalid Credentials";
                                 _entryValidation.text = @"An account with the listed credentials was not found, please proceed to registration screen via the navigation bar at the top of the applications user interface";
                             }
                             else
                             {
                                 _credentialVerification.text = @"Valid Credentials";
                                 [self performSegueWithIdentifier:@"toMainScreen" sender:self];
                             }
                         }
     ];
}
else
{
    [[FIRAuth auth] createUserWithEmail:_usernameTextField.text
                               password:_passwordTextField.text
                             completion:^(FIRUser *_Nullable user, NSError *_Nullable error)
                             {
                                 if (error.code == FIRAuthErrorCodeInvalidEmail)
                                 {
                                     _credentialVerification.text = @"Invalid Email";
                                 }
                                 else
                                 {
                                     _entryValidation.text = @"Account creation was succesful, please proceed to the login screen via the navigation bar at the top of the applications user interface";
                                 }
                             }
     ];
}
}

代码中的问题是您正在检查枚举,因为枚举的值不为零,所以它将始终为true,并且不会输入else部分,因此您需要更改两个if语句中的条件,以检查类似这样的错误代码(我不确定语法,但希望您能够理解)

更新

修改您的if-else语句,如下所示:

if (error) {
       NSLog(@"%@", error)
}else {
       //code when there is no error    
}

代码中的问题是您正在检查枚举,因为枚举的值不为零,所以它将始终为true,并且不会输入else部分,因此您需要更改两个if语句中的条件,以检查类似这样的错误代码(我不确定语法,但希望您能够理解)

更新

修改您的if-else语句,如下所示:

if (error) {
       NSLog(@"%@", error)
}else {
       //code when there is no error    
}

您不需要检查完成处理程序
NSError
,这就是编译器发出此警告的原因。因此,在您的
登录邮件中这样检查它

                          if (error.code == FIRAuthErrorCodeUserNotFound)
                             {
                                 _credentialVerification.text = @"Invalid Credentials";
                                 _entryValidation.text = @"An account with the listed credentials was not found, please proceed to registration screen via the navigation bar at the top of the applications user interface";
                             }
                             else
                             {
                _credentialVerification.text = @"Valid Credentials";
                                 [self performSegueWithIdentifier:@"toMainScreen" sender:self];
                             }

您的
createUserWithEmail
也是如此。希望它能帮助您。

您在哪里都无法检查完成处理程序
NSError
,这就是编译器发出此警告的原因。因此,在您的
登录邮件中这样检查它

                          if (error.code == FIRAuthErrorCodeUserNotFound)
                             {
                                 _credentialVerification.text = @"Invalid Credentials";
                                 _entryValidation.text = @"An account with the listed credentials was not found, please proceed to registration screen via the navigation bar at the top of the applications user interface";
                             }
                             else
                             {
                _credentialVerification.text = @"Valid Credentials";
                                 [self performSegueWithIdentifier:@"toMainScreen" sender:self];
                             }


您的
createUserWithEmail
也是如此。希望对您有所帮助。

此警告在哪一行?我将编辑代码以显示警告出现的位置。@AdityaSrivastava您现在应该可以看到更新的代码,其中显示了两个错误的位置。注意:从技术上讲,else语句中的所有内容都适用于这个“代码永远不会执行”错误,因此编辑其中的内容不会产生任何结果,我认为外部语法有问题。发布了我的答案。检查警告出现在哪一行?我将编辑代码以显示警告出现的位置。@AdityaSrivastava您现在应该可以看到更新的代码,其中显示了两个错误的位置。注意:从技术上讲,else语句中的所有内容都适用于这个“代码永远不会执行”错误,因此编辑其中的内容不会产生任何结果,我认为外部语法有问题。发布了我的答案。检查它这是非常翔实,简短和有益的。谢谢。我遇到了一个问题,if和else语句都被执行了。我的意思是,文本框将值更改为if语句中存储的值,但转换仍会发生到下一个view controller…@特洛伊木马这是不同的问题,但无论如何,请显示您正在更新的代码using@TrojanTheHorse添加打印(错误代码)在每个if语句之前,请告诉我输出,并请删除作为答案发布的代码,我已编辑了问题我正在使用NSLog(@“%ld”,(long)error.code);相反,由于print函数给了我一个“声明隐式…”错误。这是非常有用的、简短的信息。谢谢。我遇到了一个问题,if和else语句都被执行了。我的意思是,文本框将值更改为if语句中存储的值,但转换仍会发生到下一个view controller…@特洛伊木马这是不同的问题,但无论如何,请显示您正在更新的代码using@TrojanTheHorse添加打印(错误代码)在每个if语句之前,请告诉我输出,并请删除作为答案发布的代码,我已编辑了问题我正在使用NSLog(@“%ld”,(long)error.code);相反,由于print函数给了我“声明隐式…”错误。与其他答案一起,这是非常有用的,谢谢。虽然,现在的行为是,即使它显示错误语句,但无论如何,它会执行其他操作…与其他答案一起,这是非常有用的,谢谢。虽然,现在的行为是,即使它显示了错误语句,但所发生的是它仍然执行了其他操作。。。