访问 Swift 中的结构外的值 3

Access value outside of a struct in Swift 3

我正在尝试为我的 iOS 应用实施 PagingMenuController Swift 3. 请参阅 full code example here on github。在此示例中,他们在结构 PagingMenuOptions (let viewController1 = ViewController1() ...) 中创建了视图控制器。但是我不想在这里创建,而是希望能够访问在结构 PagingMenuOptions 外部 声明的 ViewController 数组。但是我得到一个错误

Struct declaration cannot close over value 'self' defined in outer scope.

知道如何实现吗?

private struct PagingMenuOptions: PagingMenuControllerCustomizable {
    fileprivate var componentType: ComponentType {
        return .all(menuOptions: MenuOptions(), pagingControllers: pagingControllers)
    }

    fileprivate var pagingControllers: [UIViewController] {
        let viewController1 = ViewController1()
        let viewController2 = ViewController2()
        return [viewController1, viewController2]
    }

    fileprivate struct MenuOptions: MenuViewCustomizable {
        var displayMode: MenuDisplayMode {
            return .segmentedControl
        }
        var itemsOptions: [MenuItemViewCustomizable] {
            return [MenuItem1(), MenuItem2()]
        }
    }

    fileprivate struct MenuItem1: MenuItemViewCustomizable {
        var displayMode: MenuItemDisplayMode {
            return .text(title: MenuItemText(text: "First Menu"))
        }
    }
    fileprivate struct MenuItem2: MenuItemViewCustomizable {
        var displayMode: MenuItemDisplayMode {
            return .text(title: MenuItemText(text: "Second Menu"))
        }
    }
}

这可以通过将 init(xxx) 函数添加到结构 PagingMenuOptions 并将 viewControllers 数组传递给该函数来完成。