为什么这个代码结果为“Type'CGPoint'不符合协议'AnyObject'”?
let mutableSet = NSMutableSet()
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
touch = touches.anyObject() as UITouch!
mutableSet.addObject(touch.locationInNode(self))
}
答案 0 :(得分:8)
NSMutableSet
只接受引用类型,但CGPoint
是结构,值类型。您可以将该点包装在NSValue
中以添加它。
mutableSet.addObject(NSValue(CGPoint: touch.locationInNode(self)))