I don't know what's the matter with Xcode. I want to create a UIPageViewController
using the initializer in one of my company project:
init(transitionStyle style: UIPageViewController.TransitionStyle,
navigationOrientation: UIPageViewController.NavigationOrientation,
options: [UIPageViewController.OptionsKey : Any]? = nil)
But Xcode keeps giving this error message.
This is my code:
let vc = UIPageViewController(transitionStyle: .scroll,
navigationOrientation: .vertical,
options: [UIPageViewController.OptionsKey.interPageSpacing: 10])
Meanwhile, in new demo project I created just now from the template Page-based App
(as bellow), it builds without any error.
How to fix/walkaround it?
The syntax was different in Swift 4. Your current project might be in Swift 4.0. Change its swift version to 4.2 and above. Or use the below code
init(transitionStyle style: UIPageViewControllerTransitionStyle,
navigationOrientation: UIPageViewControllerNavigationOrientation,
options: [String : Any]? = nil)
Swift 4.0
let vc = UIPageViewController(transitionStyle: .scroll,
navigationOrientation: .vertical,
options: [UIPageViewControllerOptionInterPageSpacingKey : 10])
Swift 4.2 and above
let vc = UIPageViewController(transitionStyle: .scroll,
navigationOrientation: .vertical,
options: [UIPageViewController.OptionsKey.interPageSpacing : 10])