首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >touches.anyObject()不再工作

touches.anyObject()不再工作
EN

Stack Overflow用户
提问于 2015-07-31 12:33:36
回答 2查看 2.1K关注 0票数 3

我有一个错误,我不知道如何处理。在……里面

代码语言:javascript
复制
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

        //Some code here

        let touch = touches.anyObject() as! UITouch
        let touchLocation = touch.locationInNode(self)
        sceneTouched(touchLocation)

}

我得到的错误"Set“没有一个名为‘anyObject’的会员。我在网上搜索了所有的内容,没有发现任何东西。我知道这与Swift最近的一些变化有关,但我不知道该如何推广它。任何帮助都将不胜感激!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-07-31 12:37:58

尝尝这个

代码语言:javascript
复制
 override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
    var touch : UITouch!
    touch = touches.first as? UITouch
    let touchLocation = touch.locationInNode(self)
    sceneTouched(touchLocation)
 }
票数 4
EN

Stack Overflow用户

发布于 2015-07-31 12:38:18

注意,Swift类型没有anyObject方法。您可以将其转换为NSSet,然后使用anyObject方法,或者只需先使用?这在Swift中对所有CollectionType都可用。

代码语言:javascript
复制
let touch = touches.first as! UITouch
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31746331

复制
相关文章

相似问题

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