Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 为什么+;=int数组在结构中不起作用?_Arrays_Swift_Struct - Fatal编程技术网

Arrays 为什么+;=int数组在结构中不起作用?

Arrays 为什么+;=int数组在结构中不起作用?,arrays,swift,struct,Arrays,Swift,Struct,我有一段代码: struct Struct { var data = [Int]() } let p = Struct(data:[1]) var a = [1, 2] var b = [3, 4] a += b p.data += b // compile error: Cannot invoke '+=' with an argument list of type '([(Int)], [Int])' 那么,为什么Swift接受向a添加一个int数组,而不向struct中的类似int

我有一段代码:

struct Struct {
  var data = [Int]()
}
let p = Struct(data:[1])

var a = [1, 2]
var b = [3, 4]
a += b
p.data += b // compile error: Cannot invoke '+=' with an argument list of type '([(Int)], [Int])'

那么,为什么Swift接受向
a
添加一个int数组,而不向
struct
中的类似int数组添加?

p
必须是变量:
var p=struct(数据:[1])
。我相信在…@MartinR Bloody Swift compiler messages>:-(每次都会误导你进入不同的迷宫。谢谢你!