Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Ryan O'Connor
Ryan O'Connor
11,282 Points

expected expression after operator- SWIFT

Swift Compiler Error. It says it is expecting an expression after operator if (index == self.pageTitles.count)

What expression is it expecting? I can't figure it out, here is the code.

func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {

    var vc = viewController as! ContentViewController
    var index = vc.pageIndex as Int

    if (index == NSNotFound)
    {
        return nil
    }

    index ++

    if (index == self.pageTitles.count)
    {
        return nil
    }

    return self.viewControllerAtIndex(index)

}

1 Answer

You have a space between index and ++ - this will most likely be causing the error. When you get compiler errors like this, the line it crashs on isn't necessarily the line with the error, you should always check backwards from the line it crash's on too.

Ryan O'Connor
Ryan O'Connor
11,282 Points

that was it, thank you very much for your help.