UITabBarController.selectedIndex类型取决于架构?

时间:2016-06-12 09:02:07

标签: ios swift architecture uitabbarcontroller uitabbar

在我的代码中,我通过为tabBarController.selectedIndex = TabBarIndex.tabA

指定适当的值来更改显示的标签
// Works when compiling for iPhone 5s
struct TabBarIndex {
    static let tabA = 0
    static let tabB = 1
    static let tabC = 2
    static let tabD = 3
}

// Works when compiling for an older device or when archiving the project
struct TabBarIndex {
    static let tabA = UInt(0)
    static let tabB = UInt(1)
    static let tabC = UInt(2)
    static let tabD = UInt(3)
}

Apple文档说var selectedIndex: Int。如果我为旧设备编译或想要将项目存档以便将其上传到App Store,我会收到以下编译错误:

Cannot assign value of type 'Int' to type 'UInt'

只有在 UInt版本替换 Int版本之后才有效 - 反之亦然。这是我必须手动更改以便在本地(或存档)编译不同设备的唯一方法 - 是否有办法不这样做?

0 个答案:

没有答案