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

前端之家收集整理的这篇文章主要介绍了swift – 编译器的这个响应是否有效?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
以下代码调用错误.我找不到任何有关这方面的信息. ‘=’操作符右侧缺少空格是一个错误.
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这样的空白来说,这也不是很荒唐.

原文链接:https://www.f2er.com/swift/319755.html

猜你在找的Swift相关文章