首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“Set<NSObject>”没有名为“anyObject”的成员。-Xcode6.3

“Set<NSObject>”没有名为“anyObject”的成员。-Xcode6.3
EN

Stack Overflow用户
提问于 2015-04-12 07:50:56
回答 2查看 10.3K关注 0票数 23

我正在检查是否选择了某个元素。

代码语言:javascript
复制
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

EN

回答 2

Stack Overflow用户

发布于 2015-04-12 08:05:53

代码语言:javascript
复制
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

票数 22
EN

Stack Overflow用户

发布于 2015-04-12 08:16:31

这将检查symbolsLayer中的多个触摸

代码语言:javascript
复制
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)
        }
    }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29584365

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档