How to get name/kind of selected item in IB

Hi,


I am newbie to Cocoa Applescript, but know the core Applescript concepts.


I have created a new CoCoa applescript application with different objects in the IB.


When I run the application, how would I get the name/type of the object I have selected in the application.


For example: There are 2 Buttons, 1 Popup button. If i select/click any one buttons, i need to get its name.

Replies

In the IBAction of the UIButton, to get the name (I think you mean the title ?):


    @IBAction func buttonAction(_ sender: AnyObject) {
        let name = (sender as! UIButton).currentTitle!
     


If you want to get the title for each state:

let name = (sender as! UIButton).title(for: UIControlState.highlighted) ?? "no name")

If no title defined for hilighted, you'll get a no name


The type :

       let type = (sender as! UIButton).buttonType..rawValue


For the rawValue corresponds to the enum UIButtonType:


case custom 0

No button style.

case system 1

A system style button, such as those shown in navigation bars and toolbars.

case detailDisclosure 2

A detail disclosure button.

case infoLight 3

An information button that has a light background.

case infoDark 4

An information button that has a dark background.

case contactAdd 5

A contact add button.

case plain 6

A standard system button without a blurred background view.


There is another type : static var roundedRect: UIButtonType

A rounded-rectangle style button.

You can connect your IB objects to action handlers - a handler can be called for example, when a button is pressed. The object calling the handler will be passed to it, so you can get its title, tag, or whatever.