ios xcode swift set nsobject

ios - ''Set<NSObject>'' no tiene un miembro llamado ''anyObject. "- Xcode 6.3



swift (2)

Estoy comprobando si un elemento ha sido seleccionado.

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)

Y esto se había compilado previamente bien en Xcode 6.2, pero con una actualización 6.3, la línea "let touch = touches.anyObject! As? UITouch" está generando el error:

''Set'' no tiene un miembro llamado ''anyObject''

He leído muchas preguntas similares, pero parece que no puedo entender mejor "Para usar el valor, primero debes" desenvolverlo ". Sobre todo porque las respuestas parecen centrarse en las notificaciones.

Muchas gracias. W


Esto comprobaría múltiples toques en 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) } } }


let touch = touches.first as? UITouch

.first puede permitirle acceder al primer objeto de UITouch.

Como Xcode 6.3 usa una versión actualizada de Swift (1.2), necesitas convertir tu código antiguo en Swift 1.2 (Editar -> convertir -> Para Swift más reciente).

Swift 1.2, usa Set ''s (nuevo en Swift) en lugar de usar NSSet ''s (antiguo en Objective-C). Por lo tanto, la función touchbegan también cambia sus parámetros de NSSet a Set.

Para obtener más información, consulte este