use*_*836 1 typing nsmutableset swift
为什么这个代码结果为"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))
}
Run Code Online (Sandbox Code Playgroud)
NSMutableSet只接受引用类型,但它CGPoint是一个结构,一个值类型.您可以将该点包装在一个中NSValue以添加它.
mutableSet.addObject(NSValue(CGPoint: touch.locationInNode(self)))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1518 次 |
| 最近记录: |