在Swift中使用if in赋值的用法 [英] Usage of where in if let assignment in Swift

查看:149
本文介绍了在Swift中使用if in赋值的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Swift手册第61页的Swift文档提示可以使用 where 来加入具有常规条件的可选绑定。然而,当我这样做时,我有一个警告,建议我用以下代码中的逗号替换 where

The Swift documentation at page 61 of the Swift manual hints to the possibility of using where to join an optional binding with a regular condition. Yet when I do it I have a warning suggesting me to substitute the where with a comma like in the following piece of code:

if let geocodingError = error as? NSError where geocodingError.code == 2


推荐答案

在Swift 3中这个语法已经改变了。

In Swift 3 this syntax has changed.

什么是

如果让x = y,a = b其中a = = x {

现在

如果让x = y,设a = b,a == x {

理由是<$ c $的每个子条款c> if ... {现在是一个独立的布尔测试。

The justification is that each sub-clause of the if ... { is now an independent boolean test.

参见Xcode 发行说明& Swift Evolution提案了解更多相关信息改变。

See the Xcode Release notes & the Swift Evolution proposal for more info about this change.

这篇关于在Swift中使用if in赋值的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆