Is this response from the compiler valid?

前端 未结 3 1509
栀梦
栀梦 2020-11-29 09:43

The following code invokes an error. I could not find any information on this is in the reference. The lack of whitespace on the right hand side of the \'=\' operator is an

相关标签:
3条回答
  • 2020-11-29 09:56

    Add a space after the =. (=[ looks too sad to be an operator.) It's probably seeing =value as a use of a (possible, but not implemented) prefix operator.

    Swift isn't entirely whitespace-agnostic like C... in particular, it uses whitespace to distinguish prefix from postfix operators (because ++i++ in C is a grammar oddity). But it's not ridiculously strict about whitespace like Python either.

    0 讨论(0)
  • 2020-11-29 09:57

    Place a space between = and [,

    let names = ["Anna", "Alex", "Brian", "Jack"]
    

    It seems that =[ is a reserved operator.

    0 讨论(0)
  • 2020-11-29 10:01

    Try adding a space between the = and [.

    When the equals sign is directly in front of the bracket, the compiler assumes that you are trying to perfom a prefix operation on the array.

    0 讨论(0)
提交回复
热议问题