'设置< NSObject的>'没有名为“anyObject”的成员。 - Xcode 6.3 [英] 'Set<NSObject>' does not have a member named 'anyObject." - Xcode 6.3

查看:137
本文介绍了'设置< 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

Thank you so much. 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(编辑 - >转换 - >到lastest 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,使用设置(在Swift中新增)而不是使用 NSSet (在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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆