Skip to content

Instantly share code, notes, and snippets.

@inso-
Last active July 7, 2020 15:54
Show Gist options
  • Save inso-/db1dbce04cc841230cb6aefedfcb1ea1 to your computer and use it in GitHub Desktop.
Save inso-/db1dbce04cc841230cb6aefedfcb1ea1 to your computer and use it in GitHub Desktop.
import UIKit
public enum Style {
case dark
case light
case `default`
}
protocol Coolable {
var isCool: Bool { get set }
}
protocol Stylable {
var style: Style { get set }
}
extension UIViewController: Stylable, Coolable {
private func holder<T>() -> Property<T> { Property.init(self) }
public var style: Style {
get { holder().wrappedValue ?? Style.default }
set { holder().wrappedValue = newValue }
}
public var isCool: Bool {
get { holder().wrappedValue ?? false}
set { holder().wrappedValue = newValue}
}
}
func test() {
let a = UIViewController()
let b = UIViewController()
a.isCool = true
b.isCool = false
print(a.isCool) // true
print(b.isCool) // false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment