Skip to content

Instantly share code, notes, and snippets.

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

Embed
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.