我正在检查是否选择了某个元素。
func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent)
{
// First, see if the game is in a paused state
if !gamePaused
{
// Declare the touched symbol and its location on the screen
let touch = touches.anyObject! as? UITouch
let location = touch.locationInNode(symbolsLayer)这在以前的Xcode6.2中编译得很好,但是在6.3更新中,"let touch = touches.anyObject!as? UITouch“这一行抛出了错误:
“‘Set”没有名为“anyObject”的成员
我读过许多类似的问题,但我似乎不能理解“要使用值,您需要首先”解开“它。”特别是因为答案似乎集中在通知上。
非常感谢。W
发布于 2015-04-12 08:05:53
let touch = touches.first as? UITouch.first允许您访问UITouch的第一个对象。
由于Xcode6.3使用的是Swift ( 1.2 )的更新版本,因此您需要将旧代码转换为Swift 1.2(编辑->,将->转换为最新的Swift)。
Swift 1.2,使用Set的(在Swift中是新的)而不是使用NSSet的(在Objective-C中是旧的)。因此,touchbegan函数也将其参数从NSSet更改为Set。
有关更多信息,请访问refer this
发布于 2015-04-12 08:16:31
这将检查symbolsLayer中的多个触摸
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent)
{
// First, see if the game is in a paused state
if !gamePaused
{
// Declare the touched symbol and its location on the screen
for touch: AnyObject in touches {
let location = (touch as! UITouch).locationInNode(symbolsLayer)
}
}
}https://stackoverflow.com/questions/29584365
复制相似问题