Skip to content

Commit e0553f0

Browse files
committed
update for 6.1, be so much cooler and swiftier
1 parent a4b5d4e commit e0553f0

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

bk2ch12p609tabBar/ch25p880tabBar/ViewController.swift

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,31 @@ import UIKit
44

55
class ViewController: UIViewController {
66
@IBOutlet var tabbar : UITabBar!
7-
var items = [UITabBarItem]()
7+
var items : [UITabBarItem] = {
8+
Array(1..<8).map {
9+
UITabBarItem(
10+
tabBarSystemItem:UITabBarSystemItem(rawValue:$0)!,
11+
tag:$0)
12+
}
13+
}()
814

915
override func viewDidLoad() {
1016
super.viewDidLoad()
11-
12-
for ix in 1 ..< 8 {
13-
self.items.append(
14-
UITabBarItem(
15-
tabBarSystemItem: UITabBarSystemItem(ix), tag: ix
16-
)
17-
)
18-
}
19-
var arr = Array(self.items[0..<4])
20-
arr.append(
21-
UITabBarItem(tabBarSystemItem: .More, tag: 0)
22-
)
23-
self.tabbar.items = arr
24-
self.tabbar.selectedItem = self.tabbar.items[0] as UITabBarItem
17+
self.tabbar.items = Array(self.items[0..<4]) + [UITabBarItem(tabBarSystemItem: .More, tag: 0)]
18+
self.tabbar.selectedItem = self.tabbar.items![0] as? UITabBarItem
2519
}
2620
}
2721

2822
extension ViewController : UITabBarDelegate {
29-
func tabBar(tabBar: UITabBar!, didSelectItem item: UITabBarItem!) {
23+
func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem!) {
3024
println("did select item with tag \(item.tag)")
3125
if item.tag == 0 {
3226
// More button
3327
tabBar.selectedItem = nil
3428
tabBar.beginCustomizingItems(self.items)
3529
}
3630
}
37-
38-
func tabBar(tabBar: UITabBar!, didEndCustomizingItems items: [AnyObject]!, changed: Bool) {
39-
self.tabbar.selectedItem = self.tabbar.items[0] as UITabBarItem
31+
func tabBar(tabBar: UITabBar, didEndCustomizingItems items: [AnyObject], changed: Bool) {
32+
self.tabbar.selectedItem = self.tabbar.items![0] as? UITabBarItem
4033
}
4134
}

0 commit comments

Comments
 (0)