I'm trying to add a default behavior on some UITextFieldDelegate's methods using protocol extensions like so :
extension ViewController: UITextFieldDelegate {
    // Works if I uncommented this so I know delegates are properly set
//    func textFieldShouldReturn(textField: UITextField) -> Bool {
//        textField.resignFirstResponder()
//        return true
//    }
}
extension UITextFieldDelegate {
    func textFieldShouldReturn(textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
}
As you may guess, the keyboard never dismiss. I can't really see where's the problem here. Is this a language limitation ? Did someone already success doing it ?
EDIT :
As @Logan suggested, default protocol's method implementation doesn't work with protocols marked as @objc. However, UITextFieldDelegate has the following signature public protocol UITextFieldDelegate : NSObjectProtocol {...}
I've test default implementation for NSObjectProtocol and it seems to works fine :
protocol Toto: NSObjectProtocol {
    func randomInt() -> Int
}
extension Toto {
    func randomInt() -> Int {
        return 0
    }
}
class Tata: NSObject, Toto {}
let int = Tata().randomInt() // returns 0
 
     
     
    