Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.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
Ios 将Int追加到[Int]类型的集合后,会得到';不完全相同';错误_Ios_Swift - Fatal编程技术网

Ios 将Int追加到[Int]类型的集合后,会得到';不完全相同';错误

Ios 将Int追加到[Int]类型的集合后,会得到';不完全相同';错误,ios,swift,Ios,Swift,这是密码 class Stack { var size: Int = 0 var items: [Int] = [] func push(element: Int) { items += element // Error - '[Int]' is not identical to 'UInt8' } func pop() -> Int { return items.removeLast() } } 所有内容

这是密码

class Stack {
    var size: Int = 0
    var items: [Int] = []

    func push(element: Int) {
        items += element // Error - '[Int]' is not identical to 'UInt8'
    }
    func pop() -> Int {
        return items.removeLast()
    }
}

所有内容都是显式类型化的。解释器如何确定我的
元素
属于
UInt8
类型?

+
的含义已更改。您只能对两个数组使用它。所以你可以说:

 items += [element]

但是,我建议改为使用
append

Neat!我想知道他们为什么不用这些变化来更新他们的在线文档?从哪里可以了解到这些模糊的变化?我非常喜欢阅读它们,如果不是因为有时过时的功能:)参见: