Using the Swift if let with logical AND operator &&

前端 未结 6 482
名媛妹妹
名媛妹妹 2021-01-30 19:13

We know that we can use an if let statement as a shorthand to check for an optional nil then unwrap.

However, I want to combine that with another expression

6条回答
  •  佛祖请我去吃肉
    2021-01-30 20:06

    I think your original proposition is not too bad. A (messier) alternative would be:

    if ((window!.rootViewController as? UITabBarController)?.viewControllers.count ?? 0) > 0 {
        println("do stuff")
    }
    

提交回复
热议问题