Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

in swift source Type of expression is ambiguous without more context

func touchesBegan(touches: NSSet, withEvents event:UIEvent) {  
    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)
        player.position.x = location.x
    }
}

it gives me this following error

Type of expression is ambiguous without more context

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This looks like Swift 2 code. The current signature is

func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  for touch in touches {
        let location = touch.locationInNode(self)
        player.position.x = location.x
    }
}

And if we are talking about Swift 2 then cast NSSet to native Set and it’s certainly withEvent (singular)

func touchesBegan(touches: NSSet, withEvent event:UIEvent) {  
    for touch in touches as Set<UITouch> {
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading