我正在检查是否选择了一个元素.
I'm checking to see if an element has been selected.
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)
这之前在 Xcode 6.2 中编译得很好,但随着 6.3 的更新,let touch = touches.anyObject!as?UITouch"这行会抛出错误:
And this had previously compiled fine in Xcode 6.2 but with a 6.3 update, the line "let touch = touches.anyObject! as? UITouch" is throwing the error:
Set"没有名为anyObject"的成员
'Set' does not have a member named 'anyObject'
我已经阅读了许多类似的问题,但我似乎无法理解要使用该值,您需要先解包"它.尤其是因为答案似乎集中在通知上.
I've read through many similar question, but I can't seem to wrap my head around "To use the value, you need to "unwrap" it first." Especially because the answers seem to focus on notifications.
非常感谢.W
let touch = touches.first as? UITouch
.first
可以让你访问 UITouch 的第一个对象.
.first
can allow you to access first object of UITouch.
由于 Xcode 6.3 使用 Swift (1.2) 的更新版本,您需要将旧代码转换为 Swift 1.2(编辑 -> 转换 -> 到最新的 Swift).
Since Xcode 6.3 uses an updated version of Swift (1.2) you need to convert your old code into Swift 1.2 (Edit -> convert -> To lastest Swift).
Swift 1.2,使用 Set
's(Swift 中的新功能)而不是使用 NSSet
's(Objective-C 中的旧功能).因此,touchbegan 函数也将其参数从 NSSet 更改为 Set.
Swift 1.2, uses Set
’s (new in Swift) instead of using NSSet
’s (old one in Objective-C). Thus the touchbegan function also changes its parameters from NSSet to Set.
欲了解更多信息,参考这个
这篇关于'设置<NSObject>'没有名为“anyObject"的成员.- Xcode 6.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!