swipeActions 모디파이어 사용
- 주의: List 뒤에가 아니라 안에 추가
- 관련된 아이템의 index를 알 수 있는 곳에 modifier을 추가하는 것이 좋다.
- swipe aciton은 여러개를 추가해도 된다.
struct SwipeActions: View {
@State private var favorites = [AppleProduct]()
@State private var allProducts = AppleProduct.sampleList
var body: some View {
List {
Section("Favorites") {
ForEach(favorites) { item in
Text(item.name)
}
}
Section("All Products") {
ForEach(allProducts) { item in
Text(item.name)
.swipeActions {
Button {
withAnimation {
favorites.append(item)
}
} label: {
Image(systemName: "hand.thumbsup")
}
}
}
}
}
}
}

배치
- edge 파라미터로 설정해주면 된다.

...
.swipeActions(edge: .leading) {
...
Full Swipe
- 절반 너비 이상을 스와이프하는 것
- Button의 액션이 실행된다.(여러개일 경우 첫번째 액션 실행)
- 따라서 가장 기본이 되는 액션을 가장 앞에 추가해야 한다.
- 비활성화는
swipeActions(allowFullSwipe: false)