-
-
Save Augustyniak/3fe2d697c51974c39d7fa9da629ec829 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
var str = "Hello, welcome in 'Safe UITabBar interface' playground. Let's start." | |
protocol UITabBarReadOnlyProtocol { | |
var selectedItem: UITabBarItem? { get } | |
var items: [UITabBarItem]? { get } | |
} | |
protocol UITabBarReadWriteProtocol { | |
var selectedItem: UITabBarItem? { get set } | |
var items: [UITabBarItem]? { get set } | |
} | |
protocol UITabBarViewReadOnlyProtocol: UITabBarReadOnlyProtocol { | |
var view: UIView { get } | |
} | |
extension UITabBarViewReadOnlyProtocol where Self: UIView { | |
var view: UIView { | |
get { | |
return self | |
} | |
} | |
} | |
extension UITabBar: UITabBarViewReadOnlyProtocol, UITabBarReadWriteProtocol {} | |
extension UITabBarController { | |
var safeTabBar: UITabBarViewReadOnlyProtocol { | |
get { | |
return self.tabBar | |
} | |
} | |
} | |
var tabBarController = UITabBarController() | |
tabBarController.safeTabBar.view.frame = CGRect(x: 0, y: 0, width: 100, height: 100) //all properties of the UIView accessible 👯 | |
tabBarController.safeTabBar.selectedItem = nil //compilation error 💀 | |
let selectedItem = tabBarController.safeTabBar.selectedItem //works like a charm! 👌 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment