One Logo Pool Ball
SuggestedActions · IOS API REFERENCE

SuggestedActionsView

struct · iOS 27.0+ · SDK 27.1

@MainActor struct SuggestedActionsView

A view that displays suggested actions for a message. The suggested actions view displays inline actions for a messaging app, next to a message, using context you provide. This view animates suggested actions as they become available. If no suggested actions are available, the view's size is zero and remains zero until they become available. At size zero, a `SuggestedActionsView` doesn't affect your surrounding layout. As a result, place the view for every message in a conversation. It doesn't introduce gaps between messages if a message doesn't have suggested actions. > Note: To display suggested actions, add the <doc://com.apple.documentation/documentation/bundleresources/entitlements/com.apple.developer.suggested-actions> entitlement to your app target. ## Customize the appearance To customize a `SuggestedActionsView`, apply standard SwiftUI view modifiers to change its appearance. Additionally, the view reads the following modifiers from its parent views: - <doc://com.apple.documentation/documentation/swiftui/view/tint(_:)>, - <doc://com.apple.documentation/documentation/swiftui/view/foregroundstyle(_:)>, - <doc://com.apple.documentation/documentation/swiftui/view/font(_:)> - <doc://com.apple.documentation/documentation/swiftui/view/buttonbordershape(_:)> ## Generate suggested actions for future use To avoid showing a loading state when the view appears, call ``generate(message:previousMessages:)`` to let the Suggested Actions framework create suggested actions and cache them for future use. When you later initialize a `SuggestedActionsView`, the framework checks the `id` of cached suggested actions based on their messages' `id` property. If it finds an `id` that matches the `id` of a new ``SuggestedActionsMessage``, the system uses the already generated suggested action. The following example shows how an app might show a `SuggestedActionsView` with information about previous messages using a capsule border shape, blue tint, and the callout font style: ```swift SuggestedActionsView( message: message.suggestedActionsMessage, previousMessages: message.previousMessages .suffix(SuggestedActionsMessage.previousMessagesLimit) .map(\.suggestedActionsMessage) ) .buttonBorderShape(.capsule) .tint(.blue) .font(.callout) ```

Members (2)

init · iOS 27.0+

init

TypeScript
static init(message: SuggestedActionsMessage, previousMessages?: Array<SuggestedActionsMessage>): Promise<SuggestedActionsView>
Swift declaration
@MainActor init(message: SuggestedActionsMessage, previousMessages: [SuggestedActionsMessage] = [])

Creates a view that shows suggested actions for the specified message. Use this initializer to present suggested actions that the framework generates for a provided message. The Suggested Actions framework analyzes the message, and previous messages you provide as additional context, then shows relevant actions that a person can take. If you call ``SuggestedActionsView/generate(message:previousMessages:)`` to generate suggested actions for future use, and later pass a ``SuggestedActionsMessage``, the Suggested Actions framework checks for suggested actions it already generated and cached. If it finds a message with a matching `id`, the `SuggestedActionsView` uses the cached result and renders the suggested actions immediately. The following example shows how an app might show a `SuggestedActionsView` with information from previous messages: ```swift struct ChatView: View { @Binding var messages: [ChatMessage] var body: some View { ForEach(messages) { message in ChatBubble(message) SuggestedActionsView( message: message.suggestedActionsMessage, previousMessages: message.previousMessages .suffix(SuggestedActionsMessage.previousMessagesLimit) .map(\.suggestedActionsMessage) ) } } } ``` - Parameters: - message: The message that you want to generate suggested actions for. - previousMessages: An array of messages that precede the provided `message`. The Suggested Actions framework uses them as context to generate suggested actions for the `message`. The system limits the number of previous messages it considers to the value of ``SuggestedActionsMessage/previousMessagesLimit``. This parameter defaults to an empty array if you don't include previous messages.

static · iOS 27.0+

generate

TypeScript
static generate(message: SuggestedActionsMessage, previousMessages?: Array<SuggestedActionsMessage>): Promise<void>
Swift declaration
nonisolated static func generate(message: SuggestedActionsMessage, previousMessages: [SuggestedActionsMessage] = []) async

Fetches and caches suggested actions for the provided message. Call this method ahead of presenting a ``SuggestedActionsView`` to generate and cache suggested actions for future use. When you later initialize the view with a ``SuggestedActionsMessage`` that has a matching `id`, the view uses the cached result and renders immediately without displaying a loading indicator. Generate suggested actions for future use when you know that a person is likely to see them soon, for example, when someone opens a conversation. You can call this method multiple times with different messages. Within a single conversation, the framework deduplicates suggestions: If a suggested action appears for an earlier message, it doesn't appear again for later messages. The following example shows how an app might use a `ChatManager` class that processes an incoming message and creates a suggested actions view: ```swift @Observable class ChatManager { private(set) var messages: [ChatMessage] = [] // Process a new incoming message and generate suggested // actions to let the Suggested Actions framework cache them for future use. func handleIncomingMessage(_ newMessage: ChatMessage) async { await SuggestedActionsView.generate( message: newMessage.suggestedActionsMessage, previousMessages: newMessage.previousMessages .suffix(SuggestedActionsMessage.previousMessagesLimit) .map(\.suggestedActionsMessage) ) messages.append(newMessage) } } ``` - Parameters: - message: The message that you want to generate suggested actions for. - previousMessages: An array of messages that precede the provided `message`. The Suggested Actions framework uses them as context to generate suggested actions for the `message`. The system limits the number of previous messages it considers to the value of ``SuggestedActionsMessage/previousMessagesLimit``. This parameter defaults to an empty array if you don't include previous messages.

Skipped declarations

1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

SuggestedActionsView.body

This protocol needs associated types that cannot yet cross the bridge.

All SuggestedActions types →