Thanks, I ended doing exactly what you suggested. On Mon, Apr 18, 2016 at 10:41 PM, Quincey Morris < [email protected]> wrote:
> On Apr 18, 2016, at 08:48 , Alex Kac <[email protected]> wrote: > > > Protocol extensions are Swift only - not ObjC compatible I believe. > > > You’re right, and I don’t see any direct way of getting around. Alternate > solutions: > > 1. If the “shared” code really is this short: > > private func configureToDismissKeyboard() { > > let tapGesture = UITapGestureRecognizer(target: self, > action: "hideKeyboard") > tapGesture.cancelsTouchesInView = true > form.addGestureRecognizer(tapGesture) > } > > func hideKeyboard() { > form.endEditing(true) > } > > > then I don’t see the value in going to any trouble to factor it out of > multiple classes. I’d recommend just duplicating it in each view > controller. (Further, ‘configureToDismissKeyboard’ doesn’t really need to > be a function. Its 3-line body could easily be written inline in > viewDidLoad.) > > Swift tends to produce a desire for over-generalization. In cases where > the simple approach is a better use of developer time, the desire should be > resisted. :) > > 2. If the actual code is more complicated, I think the problem can be > solved by a simple “transfer” method in each class: > > func hideKeyboard () { doHideKeyboard () } > > > where ‘doHideKeyboard’ is in the protocol and extension in place of > ‘hideKeyboard’. > > -- Thanks, Devarshi _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
