【发布时间】:2014-09-11 12:06:16
【问题描述】:
我创建了 Playground 并编写了这段代码:
var a = [1, 2, 3]
var b = a
a === b
游乐场给了我错误Type '[Int]' does not conform to protocol 'AnyObject'。
我做错了什么?
我正在使用 XCode 6 GM Seed。
更新
这段代码取自“The Swift Programming Language”一书,其中指出:
“Check whether two arrays or subarrays share the same storage and elements by comparing them with the identity operators (=== and !==).”
在“类和结构”一章中。
更新 2 摘自早期 Swift 规范的旧版书籍。我下载了新鲜的,没有这个词。所以身份运算符只能应用于类实例。
【问题讨论】:
-
我在 Swift Programming Language 的最新更新中找不到此摘录。
-
该死!那是旧版!我在 iBooks 中重新下载了它,但没有这样的摘录 :( iBooks 是否会在更新后自动重新下载书籍,或者我必须手动重新下载?
-
在updated document 中声明“使用这些运算符来检查两个常量或变量是否引用同一个实例:”。
标签: arrays swift identity swift-playground