Using the Swift if let with logical AND operator &&

前端 未结 6 483
名媛妹妹
名媛妹妹 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条回答
  •  猫巷女王i
    2021-01-30 19:44

    In Swift 3 Max MacLeod's example would look like this:

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

    The where was replaced by ,

提交回复
热议问题