summaryrefslogtreecommitdiff
path: root/Example Apps/Example Swift/ConnectionTabBarController.swift
blob: 3486a2aff39db8efd00cff9ff53ce9f7124750f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//
//  ConnectionTabBarController.swift
//  SmartDeviceLink-Example-Swift
//
//  Created by Joel Fischer on 9/23/21.
//  Copyright © 2021 smartdevicelink. All rights reserved.
//

import UIKit

class ConnectionTabBarController: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()

        delegate = self
        selectedIndex = AppUserDefaults.shared.lastUsedSegment
    }
}

extension ConnectionTabBarController: UITabBarControllerDelegate {
    override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
        if let index = tabBar.items?.firstIndex(where: {$0 == item}) {
            AppUserDefaults.shared.lastUsedSegment = index
        }
    }
}