A SwiftUI package that provides a flexible delete gesture you can use anywhere in your app — not limited to List or Form.
DeleteGesture brings the familiar swipe-to-delete interaction to any SwiftUI view. Unlike the built-in .onDelete modifier, which only works within List or Form, this package lets you add delete gestures to any custom view hierarchy.
- 🔓 Use Anywhere — Not bound to
ListorForm. Add delete gestures to any view. - 📱 Cross-Platform — Supports iOS (18+) and macOS (15+).
- 🎯 Haptic Feedback — Provides tactile feedback when crossing the delete threshold.
- 📖 Fully Documented — Includes comprehensive DocC documentation.
Add DeleteGesture to your project using Xcode by adding https://github.com/Comic-Star-55/DeleteGesture.git under File -> Add Package Dependencies...
Use onDelete(perform:) to make any view deletable:
import SwiftUI
import DeleteGesture
struct ContentView: View {
@State private var items = ["Item 1", "Item 2", "Item 3"]
var body: some View {
VStack {
ForEach(items, id: \.self) { item in
Text(item)
.padding()
.frame(maxWidth: .infinity)
.background(Color.gray.opacity(0.2))
.cornerRadius(8)
.onDelete{
items.removeAll { $0 == item }
}
}
}
.padding()
}
}This package includes comprehensive DocC documentation covering:
DGDeletableItem— The main view wrapper for adding delete gesturesonDelete(perform:)— The shared store for coordinating delete gesturesExample Usage— Complete code examples showing integration patterns
To build the documentation locally, use in Xcode Command + Control + Shift + D
Traditional SwiftUI delete gestures using .onDelete are restricted to List and Form views. This limitation makes it difficult to implement swipe-to-delete in:
- Custom card layouts
- Grid views
- Stacked views
- Any non-list UI patterns
DeleteGesture removes this restriction, allowing you to add intuitive delete interactions to any part of your SwiftUI interface.
- iOS 18.0+ / macOS 15.0+
See the repository for license information.