Re: Validating NSButton in Swift
Re: Validating NSButton in Swift
- Subject: Re: Validating NSButton in Swift
- From: email@hidden
- Date: Mon, 14 Dec 2015 18:58:10 +0900
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 <email@hidden> wrote:
>
>
>> On 14 Dec 2015, at 17:12, email@hidden 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 (email@hidden)
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:
This email sent to email@hidden