<!--
{
  "availability" : [
    "iOS: 12.0.0 -",
    "iPadOS: 12.0.0 -",
    "macCatalyst: 13.1.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CarPlay",
  "identifier" : "/documentation/CarPlay/CPAlertAction",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "CarPlay"
    ],
    "preciseIdentifier" : "c:objc(cs)CPAlertAction"
  },
  "title" : "CPAlertAction"
}
-->

# CPAlertAction

An object that encapsulates an action the user can perform on an action sheet or alert.

```
class CPAlertAction
```

## Overview

Use an alert action to display a button on an alert. The combination of the alert and the action styles determines the appearance of the action button. To perform an action after the user taps the button, provide a block to the action’s [`handler`](/documentation/CarPlay/CPAlertAction/handler) property.

## Topics

### Creating an alert action

[`init(title: String, style: CPAlertAction.Style, handler: CPAlertActionHandler)`](/documentation/CarPlay/CPAlertAction/init(title:style:handler:))

Creates an alert action with a title, style, and action handler.

[`init(title: String, color: UIColor, handler: CPAlertActionHandler)`](/documentation/CarPlay/CPAlertAction/init(title:color:handler:))

[`init?(coder: NSCoder)`](/documentation/CarPlay/CPAlertAction/init(coder:))

### Getting the title

[`var title: String`](/documentation/CarPlay/CPAlertAction/title)

The action button’s title.

### Getting the action style

[`var style: CPAlertAction.Style`](/documentation/CarPlay/CPAlertAction/style-swift.property)

The display style for the action button.

[`enum Style`](/documentation/CarPlay/CPAlertAction/Style-swift.enum)

Display styles for an alert’s action button.

[`var color: UIColor?`](/documentation/CarPlay/CPAlertAction/color)

### Getting the handler

[`var handler: CPAlertActionHandler`](/documentation/CarPlay/CPAlertAction/handler)

The closure that CarPlay invokes after the user taps the action button.

[`typealias CPAlertActionHandler`](/documentation/CarPlay/CPAlertActionHandler)

The declaration for an alert action handler.

## Relationships

### Conforms To

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Equatable`](/documentation/Swift/Equatable)

[`Hashable`](/documentation/Swift/Hashable)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)