In a view, there are buttons, radio Buttons and some have same IBAction. I would like to know which one was clicked ? The function resulting to the action has Sender as parameter. Unfortunately, I don't know the name of Sender. In other languages like Delphi, we can know the name of the sender with the following instruction: sender as Button).Name. Is there the same in cocoa swift?
Asked
Active
Viewed 48 times
1 Answers
0
You might be looking for the NSView.tag
property:
An integer that you can use to identify view objects in your application.
You can give your controls a tag either in code:
yourControl.tag = 10
or in the storyboard:
And then you can check the tag of the sender:
if sender.tag == 10 {
// that's yourControl!
}

Sweeper
- 213,210
- 22
- 193
- 313
-
This solve my question. Do the Sender parameter have other properties or methods ? If yes, where can I read them – AFK14 Apr 28 '19 at 08:54
-
@AlfredKrief `sender` is whatever control sent the action. If it is a button, it's a `NSButton`. If it is a text field, it's a `NSTextField`. It will have whatever properties those classes (and their superclasses) define. You can see their documentation just by googling their class names. – Sweeper Apr 28 '19 at 08:59
-
Ok, I understand. I can use the same props. and Methods for sender and the control. – AFK14 Apr 28 '19 at 09:11