我正在尝试将我的代码swift 2转到swift 3,但我无法转换遵循代码。
当我使用任何而不是AnyObject时,我会遇到错误,例如:上下文类型'any''不能与数组中的字面使用"项目:"部分。
当我用户使用AnyObject时,然后使用"名称:"零件作为AnyObject获取错误,例如:上下文类型'AnyObject'不能与Array Literal
一起使用我找不到最好的解决方案。我该怎么办?
var menus: [[String: AnyObject]] {
return [
["name": NSLocalizedString("General", comment: ""),
"items": [
MenuItem(icon: UIImage.fontAwesomeIcon(FontAwesome.Heart, textColor: TubeTrends.Settings.foregroundColor, size: TubeTrends.Settings.menuIconSize), title: NSLocalizedString("Favorites", comment: ""), action: { (indexPath) -> Void in
self.navigationController?.pushViewController(self.favoritesVideoListVC(), animated: true)
}),
]
]
在Swift 3中必须明确注释3个异源文字收集类型,例如
var menus: [[String: Any]] {
let dict : [String:Any] = ["name": NSLocalizedString("General", comment: ""),
"items": [
MenuItem(icon: UIImage.fontAwesomeIcon(FontAwesome.Heart, textColor: TubeTrends.Settings.foregroundColor, size: TubeTrends.Settings.menuIconSize), title: NSLocalizedString("Favorites", comment: ""), action: { (indexPath) -> Void in
self.navigationController?.pushViewController(self.favoritesVideoListVC(), animated: true)
}),
]
]
return [dict]
}