6
与逻辑AND运算符&&一起使用Swift
我们知道我们可以使用一条if let语句作为简写形式来检查可选的nil,然后将其解包。 但是,我想使用逻辑AND运算符将其与另一个表达式组合&&。 因此,例如,在这里,我进行可选的链接来解包,也可以选择将我的rootViewController下放到tabBarController。但是,与其嵌套if语句,不如将它们组合在一起。 if let tabBarController = window!.rootViewController as? UITabBarController { if tabBarController.viewControllers.count > 0 { println("do stuff") } } 联合捐赠: if let tabBarController = window!.rootViewController as? UITabBarController && tabBarController.viewControllers.count > 0 { println("do stuff") } } 上面给出了编译错误使用未解析的标识符'tabBarController' 简化: if let tabBarController = window!.rootViewController as? UITabBarController && true { …
93
swift
expression