Last active
July 7, 2020 15:54
-
-
Save inso-/db1dbce04cc841230cb6aefedfcb1ea1 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 | |
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