Swift 数组到 AnyObject 错误

Swift Array to AnyObject Errors

我在尝试从具有 swift 的函数 return 数组时遇到多个错误。

如果我这样做:

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() returns 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?'

无论我做什么,我都无法正确获得 return 的功能(用 AnyObject? 重播 [AnyObject]

基本上我想做的就是将数组注入 UIPageViewControllerviewControllers,但是转换数组时存在一些问题。

如有任何见解,我们将不胜感激!

我使用以下方法解决了这个数组问题:

private dynamic func pageViewControllers() -> [AnyObject!] {
    return [self.createViewController1(),self.createViewController2(),self.createViewController3()] as [AnyObject!]
}

其中每个 createViewController() 函数 returns AnyObject!:

private dynamic func createViewController1() -> AnyObject! {
    return TyphoonDefinition.withClass(TableViewController.self) {
        (definition) in
        definition.scope = TyphoonScope.Singleton
    }
}