Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typealias Decoration<T> = (T) -> Void
- struct Decorator<T> {
- let object: T
- func apply(_ decorations: Decoration<T>...) -> Void {
- decorations.forEach({ $0(object) })
- }
- }
- protocol DecoratorCompatible {
- associatedtype DecoratorCompatibleType
- var decorator: Decorator<DecoratorCompatibleType> { get }
- }
- extension DecoratorCompatible {
- var decorator: Decorator<Self> {
- return Decorator(object: self)
- }
- }
- extension UIView: DecoratorCompatible {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement