Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build an Interactive Story App with Swift 2 Creating the User Interface Programmatically Continuing Our Story

Why I am getting this error in Swift: expected ',' separator when I use #selector like in the video?

My code is identical to the one in the video but I keep getting an error message. Here is my code:

    if let firstChoice = page.firstChoice {
            firstChoiceButton.setTitle(firstChoice.title, forState: .Normal)
            firstChoiceButton.addTarget(self, action: #selector(PageController.loadFirstChoice), forControlEvents: .TouchUpInside)
        } else {
            firstChoiceButton.setTitle("Play Again", forState: .Normal)
        }

        if let secondChoice = page.secondChoice {
            secondChoiceButton.setTitle(secondChoice.title, forState: .Normal)
        }
    }
}

Swift does not like the #selector(). I can't figure out what the problem here is. Perhaps could it be that my version of Xcode isn't up to date? Thanks!

3 Answers

It's definitely possible that your version of Xcode isn't up to date! The new #selector syntax will only work in Xcode 7.3 (or newer). Which are you using?

Comb Giss
Comb Giss
589 Points

Its just Selector("loadFirstChoice")

Awesome, that was the culprit. I updated Xcode and now everything works. Thanks again Nathan! For other Treehouse users, it does take a good amount of time to update Xcode so please be sure to set aside some time to do so.