Reputation: 1014
I'm trying to see if my TabBar is nil.
In Objective-C I would do so:
if(self.tabBar != nil){
}
if I try to do this to me in swift returns this error:
'UITabBar' is not a subtype of 'NSString'
This is the code that I have to write in whole swift:
override func viewDidLayoutSubviews() {
//check tabBar not null
if (self.tabBar != nil)
{
//make changes in frame here according to orientation if any
self.tabBar.frame = CGRect(x: 00, y: 20, width:self.view.bounds.size.width, height: 49)
}
}
Upvotes: 0
Views: 1154
Reputation: 6726
The viewController's tabBarController
is an optional. The tabBar
inside a UITabBarController
is not an optional. Thus you might try:
override func viewDidLayoutSubviews() {
if let tabBarController = self.tabBarController {
// use your tabBarController
tabBarController.tabBar // the tabBar in the tabBarController is not an optional
}
}
Upvotes: 2
Reputation: 2968
Try,
let tabBar: UITabBar?
tabBar = //initialize tabBar
if tabBar != nil {
}
Hope this helps
Upvotes: 0