Create a gist now

Instantly share code, notes, and snippets.

@Augustyniak /Safe UITabBar Secret
Last active Jun 8, 2016

What would you like to do?
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