如果让逻辑AND运算符&&使用Swift &&
我们知道我们可以使用if let语句作为速记来检查可选的零,然后解包。 
 不过,我想用AND运算符&&将其与另一个expression式结合起来。 
所以,例如,在这里,我做可选的链接解开和可选地向下我的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") } } 
上面给出了编译错误使用未parsing的标识符“tabBarController”
简化:
 if let tabBarController = window!.rootViewController as? UITabBarController && true { println("do stuff") } 
这给出了编译错误条件绑定中的Bound值必须是可选的types 。 尝试了各种语法变体之后,每个variables都给出了不同的编译器错误。 我还没有find顺序和括号的组合。
所以,问题是,这是可能的,如果是的话,什么是正确的语法?
  请注意,我想用if语句来执行此操作, 而不是 switch语句或三元语句?  运营商。 
从Swift 1.2开始, 现在是可能的 。 Swift 1.2和Xcode 6.3 beta发布说明指出 :
如果让let 更强大的可选解包 – if let构造现在可以一次解包多个选项,并且包含中间布尔条件。 这可以让你expression条件控制stream程,而不需要嵌套。
用上面的语句,语法将是:
 if let tabBarController = window!.rootViewController as? UITabBarController where tabBarController.viewControllers.count > 0 { println("do stuff") } 
 这使用where子句。 
 另一个例子,这次把AnyObject到Int ,展开可选项,并检查展开的可选项是否满足条件: 
 if let w = width as? Int where w < 500 { println("success!") } 
对于那些现在使用Swift 3的人来说,“where”已经被逗号replace了。 因此相当于:
 if let w = width as? Int, w < 500 { println("success!") } 
在Swift 3中, Max MacLeod的例子看起来像这样:
 if let tabBarController = window!.rootViewController as? UITabBarController, tabBarController.viewControllers.count > 0 { println("do stuff") } 
 在where被取代, 
马克斯的答案是正确的,也是这样做的一种方式。 注意虽然这样写:
 if let a = someOptional where someBool { } 
  someOptionalexpression式将首先解决。 如果失败,则不会评估someBoolexpression式(短路评估,如您所期望的那样)。 
如果你想这样写,可以这样做:
 if someBool, let a = someOptional { } 
 在这种情况下,首先评估someBool ,并且只有评估为true时, someOptional评估someOptionalexpression式。 
这不可能。
从Swift语法
语法陈述的语法
if-statement→ if if-condition code-block else-clauseopt
if-condition→expression | 宣言
else-clause→ else code-block | 否则 if语句
if语句中任何条件的值必须具有符合BooleanType协议的types。 该条件也可以是可选绑定声明,如可选绑定中所述
if-condition必须是expression式或声明。 你不能同时拥有expression和声明。
  let foo = bar是一个声明,它不计算符合BooleanType的值。 它声明一个常量/variablesfoo 。 
您的原始解决scheme已经足够好了,结合这些条件可读性更强。
我认为你原来的主张不错。 (梅西耶)替代scheme是:
 if ((window!.rootViewController as? UITabBarController)?.viewControllers.count ?? 0) > 0 { println("do stuff") }