-5

The error is "Initializer for conditional binding must have Optional type, not 'UITabBarItem'"

     lass BaseTabBarViewController: UITabBarController {

override func viewDidLoad() {
    super.viewDidLoad()


    //The code below is the reason I get error for
     if let notif = (self.tabBar.items?[2])! as UITabBarItem {
        NotificationManager.sharedInstance.notifTabbar = notif
    }else{
        //            NotificationManager.sharedInstance.notifTabbar.badgeValue = ""
    }
  • 1
    The error answers itself. Read it again and ponder – NSNoob Jan 26 '16 at 07:06
  • 1
    Possible duplicate of [If Let Error - Initializer for conditional binding must have Optional type, not 'UITableView'](http://stackoverflow.com/questions/31038759/if-let-error-initializer-for-conditional-binding-must-have-optional-type-not) – NSNoob Jan 26 '16 at 07:07

1 Answers1

1

anytime you're doing an if let you want the initializer to be an optional

for example

if let hello = world as? String {
    // do blah
}

a quick easy way to know whether your if let ______ is an optional is to click on the world and look at your right panel and click on the ? icon.

jasonnoahchoi
  • 871
  • 5
  • 16