I'm trying to catch up with this protocol-oriented-programming coolness using Swift 2 but I'm currently quite lost.
I'm trying to apply the theory to practical use cases so let's start with the most obvious:
Let's say I have a UITextField
and I want to have many protocols (e.g. phone, numeric, lengthLimited…) that conform to UITextFieldDelegate
and override the textField:shouldChangeCharactersInRange:replacementString
method to accomplish the desired behavior.
Is it even possible to have a "Extensions.swift" file with this extensions and assign the desired protocols to a UITextField
(e.g. numeric, lengthLimited)? That would be very useful. If so, is there a way to assign a protocol to, let's say, a UITextField
outlet or I'd need to subclass a UITextField
and make it conform the desired protocols? If this is the case, then I don't see too much advantage in using protocols extensions over good old subclassing.