问题
My code was working well in Xcode 6. But, after updating to Xcode 7 I got nearly 20 errors and 50 warnings.This might be some syntax change in Swift 2
Solved all those but can't figure out this one : Downcast from UITabBarItem? to UITabBarItem only unwraps optionals; did you mean to use '!'
let tabItems = tabBar.items as! [UITabBarItem] // Error in this line
for (index, value) in enumerate(tabItems)
{
var imageName = imageNames[index]
value.image = UIImage(named: imageName)
value.imageInsets = UIEdgeInsetsMake(5.0, 0, -5.0, 0)
}
Please help! Thanks in advance
回答1:
Try this:
if let tabItems = tabBar.items as [UITabBarItem]? {
for (index, value) in tabItems.enumerate()
{
var imageName = imageNames[index]
value.image = UIImage(named: imageName)
value.imageInsets = UIEdgeInsetsMake(5.0, 0, -5.0, 0)
}
}
You see the error because items now have type [UITabBarItem]?
来源:https://stackoverflow.com/questions/32847817/downcast-from-uitabbaritem-to-uitabbaritem-only-unwraps-optionals-did-you-mean