我在尝试使用 swift 从函数返回数组时遇到多个错误。
如果我这样做:
private dynamic func rootHomePageViewController() -> AnyObject? {
return TyphoonDefinition.withClass(RootHomePageViewController.self) {
(definition) in
definition.useInitializer("style:navigationOrientation:options:") {
(initializer) in
initializer.injectParameterWith(UIPageViewControllerTransitionStyle.Scroll.rawValue) // must convert to raw value - watch for errors here
initializer.injectParameterWith(UIPageViewControllerNavigationOrientation.Vertical.rawValue) // must convert to raw value - watch for errors here
initializer.injectParameterWith(nil)
}
definition.injectMethod("setViewControllers:direction:animated:completion:", parameters: {
(method) in
method.injectParameterWith([self.pageViewController1(),self.pageViewController2(),self.pageViewController3()])
method.injectParameterWith(UIPageViewControllerNavigationDirection.Forward.rawValue)
method.injectParameterWith(false)
method.injectParameterWith(nil)
})
}
}
我得到错误:Cannot convert the expression's type '$T11' to type 'AnyObject?'
注意,self.pageViewController1()
返回 AnyObject? 和其他两个功能一样
如果我method.injectParameterWith(self.rootHomePageViewControllerPages)
用这个函数替换那里的数组(创建一个数组):
private dynamic func rootHomePageViewControllerPages() -> [AnyObject] {
return [self.pageViewController1(),self.pageViewController2(),self.pageViewController3()] as [AnyObject]!
}
我得到错误:Cannot convert the expression's type 'Array' to type 'AnyObject?'
无论我做什么,我都无法让函数正确返回([AnyObject]
使用回放AnyObject?
等)
基本上我要做的就是将数组注入到viewControllers
of UIPageViewController
,但是转换数组存在一些问题。
任何见解将不胜感激!