加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 编译器的这个响应是否有效?

发布时间:2020-12-14 05:36:45 所属栏目:百科 来源:网络整理
导读:以下代码调用错误.我找不到任何有关这方面的信息. ‘=’操作符右侧缺少空格是一个错误. let names =["Anna","Alex","Brian","Jack"] 此语法的任何其他组合都会编译.任何人知道,如果这是真的无效的语法,我们现在知道的Swift? 编辑:错误响应是:Prefix / pos
以下代码调用错误.我找不到任何有关这方面的信息. ‘=’操作符右侧缺少空格是一个错误.
let names =["Anna","Alex","Brian","Jack"]

此语法的任何其他组合都会编译.任何人知道,如果这是真的无效的语法,我们现在知道的Swift?

编辑:错误响应是:Prefix / postfix’=’被保留

答案:这段摘录似乎回答了我的问题.我只是找不到最长的时间:

The whitespace around an operator is used to determine whether an
operator is used as a prefix operator,a postfix operator,or a binary
operator. This behavior is summarized in the following rules:

If an operator has whitespace around both sides or around neither
side,it is treated as a binary operator. As an example,the +
operator in a+b and a + b is treated as a binary operator. If an
operator has whitespace on the left side only,it is treated as a
prefix unary operator. As an example,the ++ operator in a ++b is
treated as a prefix unary operator. If an operator has whitespace on
the right side only,it is treated as a postfix unary operator. As an
example,the ++ operator in a++ b is treated as a postfix unary
operator. If an operator has no whitespace on the left but is followed
immediately by a dot (.),it is treated as a postfix unary operator.
As an example,the ++ operator in a++.b is treated as a postfix unary
operator (a++ . b rather than a ++ .b).

摘录自:苹果公司“Swift编程语言”iBooks. https://itun.es/us/jEUH0.l

在=之后添加一个空格. (= [看起来太难以成为一个运算符.)可能看到=值作为(可能的,但未实现的)前缀运算符的使用.

特别是,Swift并不完全是空白无关的,特别是使用空格区分前缀和后缀操作符(因为我在C中是一个语法奇怪).但是对于像Python这样的空白来说,这也不是很荒唐.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读