Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- // Removing the subclassing from NSObject fixes the problem
- class Animal: NSObject {
- }
- protocol Named {
- init(name: String)
- }
- protocol AnimalSpecification {
- associatedtype AnimalType: Animal
- }
- extension AnimalSpecification where AnimalType: Named {
- func animal(named name: String) -> AnimalType {
- return AnimalType(name: name)
- }
- }
- class Dog: Animal, Named {
- let name: String
- required init(name: String) {
- self.name = name
- super.init()
- }
- }
- struct Kennel: AnimalSpecification {
- typealias AnimalType = Dog
- }
- let kennel = Kennel()
- kennel.animal(named: "Brian")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement