Cannot access tabBar element index using swift

Environment: xcode 6GM, Swift language. I set the image color of the tabBar element using this code in xcode 6 beta2

var cameraTab : UITabBarItem = self.tabBar.items[1] as UITabBarItem 

But now in xcode 6GM it gives an error. Error: [AnyObject]? doesn't have a member named 'subscript'

+9
ios swift xcode6 uitabbaritem
source share
2 answers

Optional - you can:

  if let items = self.tabBar.items { println("\(items[1])") } 

or

  var cameraTab : UITabBarItem = self.tabBar.items![1] as UITabBarItem 
+11
source share
Property

items optional for tabBar . Try completing an additional chain:

 var cameraTab : UITabBarItem = self.tabBar.items?[1] as UITabBarItem 
+1
source share

All Articles