Re: Validating NSButton in Swift
Re: Validating NSButton in Swift
- Subject: Re: Validating NSButton in Swift
- From: Luc Van Bogaert <email@hidden>
- Date: Mon, 14 Dec 2015 08:42:57 +0100
> On 14 Dec 2015, at 00:18, Quincey Morris <email@hidden> wrote:
>
> On Dec 13, 2015, at 14:59 , Luc Van Bogaert <email@hidden <mailto:email@hidden>> wrote:
>>
>> I have a NSButton subclass that I want to conform to NSValidatedUserInterfaceItem, so I can call validateUserInterfaceItem: on a validator passing the button as a parameter. This requires my subclass to implement two methods: action() and tag(). The compiler complains about the selectors being identical to the 'action' and 'tag' selectors in superclass NSControl.
>
> What do your subclass implementations look like (the signature, not the body)?
>
> According to the documentation, NSControl already has the conforming properties, so you don’t need to define your own. Just assign the correct values to the existing properties.
>
> However, the Swift version of NSValidatedUserInterfaceItem declares the properties as methods, so this may be confusing the issue. In Obj-C, it’s all the same thing — the getter for “action” is also the method “action”, but I’m not sure what happens during bridging. (It ought to realize they’re the same thing.)
>
> What happens if you *don’t* declare action and tag in your subclass? Is there a non-conformance warning?
I've defined the subclass like this:
class ValidatedButton: NSButton, ValidatedControl {
I've defined ValidatedControl like this:
protocol ValidatedControl: NSValidatedUserInterfaceItem {
This results in a compiler error: Type ValidatedButton does not conform to protocol NSValidatedUserInterfaceItem.
I've tried overriding the NSControl properties 'action' and 'tag', but the error remains.
--
Luc
_______________________________________________
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