2015-04-11 22 views
23

sto controllando per vedere se è stato selezionato un elemento'Set <NSObject>' non ha un membro denominato 'ANYOBJECT "-.. Xcode 6.3

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) 

e questo ha avuto precedentemente compilato bene in Xcode 6.2, ma con un aggiornamento 6.3, la linea "let touch = touches.anyObject! come? UITouch "sta gettando l'errore:

'Set' non ha un membro denominato 'ANYOBJECT'

Ho letto attraverso molte domanda simile, ma non riesco ad avvolgere la mia testa intorno" Per usare il valore, è necessario “scartare” per primo." Soprattutto perché le risposte sembrano concentrarsi sulle notifiche.

Grazie mille. W

+0

duplicati di http://stackoverflow.com/questions/28771896/overriding-method-with-selector-touchesbeganwithevent -has-incompatible-type? –

+0

Grazie Martin R. L'ho provato, ma sembra non essere esattamente il problema, cambiando ciò che hai suggerito "override func touchesBegan (tocca: Set , withEvent event: UIEvent) { if let touch = touches.first come? UITouch {"restituisce l'errore 'Set non ha un membro chiamato' first '. Ecco perché è apparso che ha qualcosa a che fare con la classificazione come array? – Willie

+0

Strano, il codice viene compilato nel mio progetto Xcode 6.3 –

risposta

20
let touch = touches.first as? UITouch 

.first può permettere di accedere primo oggetto della UITouch

Poiché Xcode 6.3 utilizza una versione aggiornata di Swift (1.2) è necessario convertire il vecchio codice in Swift 1.2 (Modifica -> Converti -> A lastest Swift).

Swift 1.2, utilizza Set (nuovo in Swift) invece di utilizzare NSSet (vecchio in Objective-C). Quindi la funzione touchbegan cambia anche i suoi parametri da NSSet a Set.

Per ulteriori informazioni, refer this

+0

Spiega aggiungendo qualche altro codice o link di riferimento per migliorare la risposta – TheUknown

+0

Questo è il riferimento https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIRes ponder_Class/index.html # // apple_ref/occ/instm/UIResponder/touchBegan: withEvent: –

+2

Grazie. Puoi modificare la tua risposta e aggiungere la stessa? e spiega di più, quindi tutti capiscono. SO non è pensato per condividere link SOLO, ma spiegare e dare un link di riferimento – TheUknown

3

Ciò verificare la presenza di molteplici tocchi in symbolsLayer

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) 
     } 
    } 
} 
+0

Questo sembra averlo risolto! Grazie mille Martin! – Willie

Problemi correlati