在 Swift 1.2 (Xcode 6.3 beta) 中,有了几个新的语言特性,New native Set data structure 则是之一,提供了桥接 NSSet
的原生 Set
数据结构,可以像操作 Array
和 Dictionary
一样操作 Set
。
所以 touchesBegan 相关方法也变了,现在你可以这样写:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
if let touch = touches.first as? UITouch {
// ...
}
super.touchesBegan(touches , withEvent:event)
}
参考:Swift Blog - Swift 1.2 and Xcode 6.3 beta