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

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.