标签:swift
Swift 中的数组是由结构体实现的:
struct Array<T> : MutableCollection, Sliceable { typealias Element = T var startIndex: Int { get } var endIndex: Int { get } subscript (index: Int) -> T func generate() -> IndexingGenerator<T[]> typealias SliceType = Slice<T> subscript (subRange: Range<Int>) -> Slice<T> init(_ buffer: ArrayBuffer<T>) }
而数组的恒等 === 在文档中是这么说的:
Check whether two arrays or subarrays share the same storage and elements by comparing them with the identity operators (===
and !==
).
数组的恒等 === 判断即判断两个数组所指向的元素存储区是否相同。
但 XCode 6 Beta 测试下来,结果大为迥异:
var a = [1, 2, 3] var b = a var c = a println("a === a: \(a === a), b === c: \(b === c)");
a === a: false, b === c: false
这应该是编译器的一个 BUG。[Swift] 数组恒等 === 的 bug?!,布布扣,bubuko.com
标签:swift
原文地址:http://blog.csdn.net/kesalin/article/details/30532433