Why does this code results to "Type 'CGPoint' does not conform to protocol '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))
}
NSMutableSet
only accepts reference types, but CGPoint
is a struct, a value type. You can wrap the point in an NSValue
to add it.
mutableSet.addObject(NSValue(CGPoint: touch.locationInNode(self)))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.