Make sure you have specified the type of the returned object correctly. In your case, a UIViewController?
func myMethod() -> UIViewController? {
return (index == self.pagesTitles.count || index == NSNotFound) ? nil : viewControllerAtIndex(++index)
}
source
to share