Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. typealias Decoration<T> = (T) -> Void
  2.  
  3. struct Decorator<T> {
  4. let object: T
  5. func apply(_ decorations: Decoration<T>...) -> Void {
  6. decorations.forEach({ $0(object) })
  7. }
  8. }
  9.  
  10. protocol DecoratorCompatible {
  11. associatedtype DecoratorCompatibleType
  12. var decorator: Decorator<DecoratorCompatibleType> { get }
  13. }
  14.  
  15. extension DecoratorCompatible {
  16. var decorator: Decorator<Self> {
  17. return Decorator(object: self)
  18. }
  19. }
  20.  
  21. extension UIView: DecoratorCompatible {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement