'设置<NSObject>'没有名为“anyObject"的成员.- Xcode 6.3

#39;Setlt;NSObjectgt;#39; does not have a member named #39;anyObject.quot; - Xcode 6.3(设置lt;NSObjectgt;没有名为“anyObject的成员.- Xcode 6.3)
本文介绍了'设置<NSObject>'没有名为“anyObject"的成员.- Xcode 6.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检查是否选择了一个元素.

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.

欲了解更多信息,参考这个

这篇关于'设置&lt;NSObject&gt;'没有名为“anyObject"的成员.- Xcode 6.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)