簡體   English   中英

touches.anyObject()不再起作用

[英]touches.anyObject() no longer working

我有一個我不知道該如何處理的錯誤。

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)

}

我收到錯誤“集”沒有名為“ anyObject”的成員。我一直在互聯網上搜索但一無所獲。我知道它與Swift中的某些最新更改有關,但我不知道該如何處理它,任何幫助將不勝感激!

嘗試這個

 override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
    var touch : UITouch!
    touch = touches.first as? UITouch
    let touchLocation = touch.locationInNode(self)
    sceneTouched(touchLocation)
 }

請注意,Swift Set類型沒有anyObject方法。 您可以將其強制轉換為NSSet,然后使用anyObject方法,也可以僅使用first? 可供Swift中的所有CollectionType使用。

let touch = touches.first as! UITouch

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM