Skip to content

Instantly share code, notes, and snippets.

@littlebobert
Created July 25, 2017 16:24
Show Gist options
  • Save littlebobert/f3cf62fb8b3ab781b9d39befecd1585c to your computer and use it in GitHub Desktop.
Save littlebobert/f3cf62fb8b3ab781b9d39befecd1585c to your computer and use it in GitHub Desktop.
protocol MyProtocol {
func method() -> String
}
extension MyProtocol {
func method() -> String {
return "foo"
}
}
class ParentClass {
func method() -> String {
return "bar"
}
}
class ChildClass: ParentClass, MyProtocol {
}
@mvyrko
Copy link

mvyrko commented Jul 26, 2017

protocol MyProtocol : NSObjectProtocol {
    
    func doThing()
    
    func doOtherThing()
    
}

extension MyProtocol {
    
    func doThing() {
        print("default")
    }
}

class Parent : NSObject {
    
    
}

extension Parent : MyProtocol {
    func doOtherThing() {
        print("parent doOtherThing")
    }

    func doThing() {
        print("parent doThing")
    }
}

class Child : Parent {
    
    override func doThing() {
        print("child doThing")
    }
    
}

//extension MyProtocol where Self : Parent {
//    
//    func doThing() {
//        print("parent")
//    }
//    
//}
//
//extension MyProtocol where Self : Child {
//    
//    func doThing() {
//        print("extension child")
//    }
//    
//}

//
//
//extension Child : MyProtocol {
//    
//    func doOtherThing() {
//        print("child")
//    }
//
//    
//}

let b1 = Child()

b1.doOtherThing()
b1.doThing()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment