Skip to content

Instantly share code, notes, and snippets.

@Augustyniak
Last active June 8, 2016 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Augustyniak/3fe2d697c51974c39d7fa9da629ec829 to your computer and use it in GitHub Desktop.
Save Augustyniak/3fe2d697c51974c39d7fa9da629ec829 to your computer and use it in GitHub Desktop.
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