if else语句会发生什么?

时间:2015-11-18 11:10:17

标签: ios

我想知道if else语句会发生什么。例如,在下面的逻辑中,如果用户既没有设置TouchID也没有设置用于登录的PIN码,则我会在底部捕获所有else语句。

1)如果上面的if statement被评估为真或假,那么else语句会占用任何系统资源吗?

2)似乎有多种方法可以将用户发送到viewcontroller,您可以拥有presetViewController()performSegueWithIdentifier()。哪个是"正确"方法

  func chooseTouchIDorPINLayout(){

        if touchIDBtn == 1{
            //do something

        }else if touchIDBtn == 2{
            // do something else

        }else{
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let onboardingNavigationController = storyboard.instantiateViewControllerWithIdentifier("onboardingNavigationController")
            self.presentViewController(onboardingNavigationController, animated: true, completion: nil)
        }
    }

非常感谢任何意见 - 谢谢!

2 个答案:

答案 0 :(得分:2)

  1. 不,当条件评估为true时,将跳过表达式的其余部分。

  2. 没有正确的方法。这取决于:

    • 如果转换是通过segue在Interface Builder中设计的,请使用performSegueWithIdentifier
    • 如果转换是按代码设计的,请使用presentViewController

答案 1 :(得分:0)

关于if语句, 如果条件为真,则解释器会跳过else语句并且不使用系统资源

相关问题