# Swipe Actions

{% tabs %}
{% tab title="💈範例" %}

```swift
// Some code
struct AccountView: View {
    
    // view states
    @State var isDeleted = false
    
    // view body
    var body: some View {
        NavigationView {                        // navigation view
            List {                              // list
                Section {
                    // conditional view ⭐️
                    if !isDeleted {
                        Link(destination: URL(string: "https://apple.com")!) {
                            HStack {
                                Label("Apple", systemImage: "house")
                                Spacer()
                                Image(systemName: "link").tint(.secondary)
                            }
                        }
                        .swipeActions {    // swipe actions ⭐️
                            
                            // first action (default action?)
                            Button {
                                isDeleted = true
                            } label: {
                                // ⭐️ 雖然用 `Label`，但只會顯示圖示。
                                Label("Delete", systemImage: "trash")
                            }.tint(.red)    // override button color ⭐️
                            
                            // second action
                            Button {} label: {
                                Label("Pin", systemImage: "pin")
                            }.tint(.yellow)
                        }
                    }
                    
                    // Link
                    Link(destination: URL(string: "https://youtube.com")!) {
                        HStack {
                            Label { Text("YouTube") } icon: {
                                Image(systemName: "tv")
                                    .foregroundColor(.red)
                            }
                            Spacer()
                            Image(systemName: "link").tint(.secondary)
                        }
                    }
                }

            }
            .listStyle(.insetGrouped)           // list style
            .navigationTitle("Account")         // navigation title
        }
    }
}
```

{% endtab %}

{% tab title="📘 手冊" %}

* View
  * [Input and Events](https://developer.apple.com/documentation/swiftui/view-input-and-events)
    * [.swipeActions(edge:allowsFullSwipe:content:)](https://developer.apple.com/documentation/swiftui/view/swipeactions\(edge:allowsfullswipe:content:\))
      {% endtab %}

{% tab title="📗 參考" %}

* Design+Code - [States and Swipe Actions](https://designcode.io/swiftui-ios15-states-swipe-actions)
* Hacking with Swift - [How to add custom swipe action buttons to a List row](https://www.hackingwithswift.com/quick-start/swiftui/how-to-add-custom-swipe-action-buttons-to-a-list-row)
* Use Your Loaf - [SwiftUI Swipe Actions](https://useyourloaf.com/blog/swiftui-swipe-actions/)
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/ios/swiftui/view/swipe-actions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
