Reputation: 157
My code was working well in Xcode6
. But, after updating to Xcode7
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 '!'
The below is the actual code:
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)
}
It shows me 1 error
When I tried doing 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)
}
}
It is showing me 5 Errors::
- "_UTTypeCopyPreferredTagWithClass", referenced from: -[PFFile _mimeType] in Parse(PFFile.o) 2. "_UTTypeCreatePreferredIdentifierForTag", referenced from: -[PFFile _mimeType] in Parse(PFFile.o) 3. "_kUTTagClassFilenameExtension", referenced from: -[PFFile _mimeType] in Parse(PFFile.o) 4."_kUTTagClassMIMEType", referenced from: -[PFFile _mimeType] in Parse(PFFile.o) ld: symbol(s) not found for architecture x86_64 5.clang: error: linker command failed with exit code 1 (use -v to see invocation)
Please help! Thanks in advance
Upvotes: 0
Views: 533
Reputation: 679
If there are some TabBarItems, tabBar.items will return you an array of UITabBarItem. If not it will return you nil (It is an optional ). So it would be "dumb" to cast it again to [UITabBarItem]. this is like saying: I have many apples, make some apples out of it. BUT you need to handle the case that tabBar.items is nil. So you just need to unwrap tabBar.items by adding an "!" to it like this:
let tabItems = tabBar.items!
This should work :)
Upvotes: 0