<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIAction",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIAction"
  },
  "title" : "UIAction"
}
-->

# UIAction

A menu element that performs its action in a closure.

```
@MainActor class UIAction
```

## Overview

Create a [`UIAction`](/documentation/UIKit/UIAction) object when you want a menu element that performs its action in a closure. The following example adds an action-based menu to the File menu:

```swift
// Create a closure-based action to use as a menu element.
let refreshAction = UIAction(title: "Refresh") { (action) in
    print("Refresh the data.")
}

// Use the .displayInline option to avoid displaying the menu as a submenu,
// and to separate it from the other menu elements using a line separator.
let refreshMenuItem = UIMenu(title: "", options: .displayInline, children: [refreshAction])

// Insert the menu into the File menu before the Close menu.
builder.insertSibling(refreshMenuItem, beforeMenu: .close)
```

## Topics

### Creating an action

[`init(title:subtitle:image:identifier:discoverabilityTitle:attributes:state:handler:)`](/documentation/UIKit/UIAction/init(title:subtitle:image:identifier:discoverabilityTitle:attributes:state:handler:))

Creates an action with the specified title, subtitle, image, identifier, discoverability title, attributes, state, and handler.

[`init(title:image:identifier:discoverabilityTitle:attributes:state:handler:)`](/documentation/UIKit/UIAction/init(title:image:identifier:discoverabilityTitle:attributes:state:handler:))

Creates an action with the specified title, image, identifier, discoverability title, attributes, state, and handler.

[`actionWithTitle:image:identifier:handler:`](/documentation/UIKit/UIAction/actionWithTitle:image:identifier:handler:)

Creates an action with the specified title, image, identifier, and handler.

[`actionWithHandler:`](/documentation/UIKit/UIAction/actionWithHandler:)

Creates an action with the specified handler.

[`captureTextFromCamera(responder:identifier:)`](/documentation/UIKit/UIAction/captureTextFromCamera(responder:identifier:))

Creates an action for capturing text using the device’s camera.

[`UIAction.Identifier`](/documentation/UIKit/UIAction/Identifier-swift.struct)

A type that represents an action identifier.

[`UIActionHandler`](/documentation/UIKit/UIActionHandler)

A type that defines the closure for an action handler.

### Getting information about the action

[`title`](/documentation/UIKit/UIAction/title)

The action’s title.

[`image`](/documentation/UIKit/UIAction/image)

The action’s image.

[`identifier`](/documentation/UIKit/UIAction/identifier-swift.property)

The unique identifier for the action.

[`discoverabilityTitle`](/documentation/UIKit/UIAction/discoverabilityTitle)

An elaborated title that explains the purpose of the action.

[`attributes`](/documentation/UIKit/UIAction/attributes)

The attributes indicating the style of the action.

[`state`](/documentation/UIKit/UIAction/state)

The state of the action.

[`sender`](/documentation/UIKit/UIAction/sender)

The object responsible for the action handler.

### Initializers

[`init(title:subtitle:image:selectedImage:identifier:discoverabilityTitle:attributes:state:handler:)`](/documentation/UIKit/UIAction/init(title:subtitle:image:selectedImage:identifier:discoverabilityTitle:attributes:state:handler:))



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)