Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. import Foundation
  2.  
  3. // Removing the subclassing from NSObject fixes the problem
  4. class Animal: NSObject {
  5. }
  6.  
  7. protocol Named {
  8. init(name: String)
  9. }
  10.  
  11. protocol AnimalSpecification {
  12. associatedtype AnimalType: Animal
  13. }
  14.  
  15. extension AnimalSpecification where AnimalType: Named {
  16. func animal(named name: String) -> AnimalType {
  17. return AnimalType(name: name)
  18. }
  19. }
  20.  
  21. class Dog: Animal, Named {
  22. let name: String
  23. required init(name: String) {
  24. self.name = name
  25. super.init()
  26. }
  27. }
  28.  
  29. struct Kennel: AnimalSpecification {
  30. typealias AnimalType = Dog
  31. }
  32.  
  33. let kennel = Kennel()
  34. kennel.animal(named: "Brian")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement