1

为什么此代码会导致“类型 '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))
}
4

1 回答 1

8

NSMutableSet只接受引用类型,但是CGPoint是一个结构,一个值类型。您可以将点包装在 anNSValue中以添加它。

mutableSet.addObject(NSValue(CGPoint: touch.locationInNode(self)))
于 2014-11-12T14:48:25.750 回答