Yeah this was one of those little stumpers. The control implements the methods to be eligible for being validated but shouldn't validate itself. A controller or something else in the responder chain that knows about app state should do validation.
The docs should be bugged. Sent from my iPhone > On Dec 14, 2015, at 6:27 PM, Roland King <r...@rols.org> wrote: > > >> On 14 Dec 2015, at 17:12, dangerwillrobinsondan...@gmail.com wrote: >> >> The bug should be that it gives you a wrong message, because it already >> conforms to the protocol because it inherits from a class that conforms to >> the protocol. >> >> All you should have to do is implement an override of the methods to do >> custom stuff or of the properties. >> You shouldn't declare conformity to NSValidatedUserInterfaceItem because it >> already confirms earlier in its ancestry. > > Nope. That’s wrong for 2 reasons. > > Firstly although NSControl does have the methods on it to conform to the > protocol in Objective C, it doesn’t actually declare that it conforms to the > protocol anywhere so you don’t get the actual conformance from the bridge > over to Swift. Its conformance is informal, not formal. > > Secondly, the methods on NSControl which implement tag and action are > properties in Objective C, not methods. In objective C that doesn’t matter as > properties just end up being two methods and the getter method in that case > has the right signature for the protocol so, in objective C, you can subclass > from any subclass of NSControl, declare protocol conformance at that point, > and it works. Swift however imports the properties as properties, not a pair > of class functions and properties do not make a class conform to a protocol > which requires functions, which the protocol in this instance does. Neither > can you override the property with a same-named method, so you can’t do it. > > I did ask earlier if Luc can declare the conformance in objective-C, > literally by making an NSValidatedButton subclass of NSButton which does > nothing but formally declare the protocol conformance and then use that in > swift. My thinking there is that the formal conformance to the protocol in > objc will mean the object is correctly tagged in swift as already conforming. > I don’t see another way to do it. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com