想建立一个元组的数组,来简单存放构建 TabViewController 的信息首先我的做法是

1
2
3
4
5
6
7
let homeTab = (vc: VYHomeViewController(), title: "Home", image: "home_gray", selectedImage: "home_blue")
let infoTab = (vc: VYInformationViewController(), title: "Info", image: "home_gray", selectedImage: "home_blue")
let marketTab = (vc: VYMarketViewController(), title: "Market", image: "home_gray", selectedImage: "home_blue")
let userTab = (vc: VYUserCenterViewController(), title: "Me", image: "home_gray", selectedImage: "home_blue")

// 下面报错:Heterogeneous collection literal could only be inferred to '[Any]'; add explicit type annotation if this is intentional
let data = [homeTab, infoTab, marketTab, userTab]

但是会报错,Xcode 的修改提示是后面添加 as [Any]

1
let data = [selfSelectedTab, infoTab, marketTab, userTab] as [Any]

但是这样做已经不是原来的做一个元组数组的初衷了。无法在遍历数组的时候使用命名元组来获取信息