Search code examples
swiftmacoscocoaxcode-storyboard

Missing Identifier for Radio Button when trying to identify the Sender


I'm trying to identify the clicked radio button using the Interface builder identifier.

enter image description here

 @IBAction func text_radio_changed(_ sender: Any) {
        let button:NSButton = sender as! NSButton
        let id:String = button.accessibilityIdentifier()
        print("===========>"+id)
    }

But the console keeps printing this

===========>

There is no identifier


Solution

  • button.accessibilityIdentifier is the Accessibility Identity Identifier. The Identity Identifier is button.identifier.

    @IBAction func text_radio_changed(_ sender: Any) {
        let button:NSButton = sender as! NSButton
        let id:String = button.identifier!.rawValue
        print("===========>"+id)
    }