A toast notification library for SwiftUI.

- Easy-to-use toast notifications
- Support for custom icons, messages, and buttons
- Seamless integration with SwiftUI
- Dark mode support
- Slide gesture to dismiss
- Loading state interface with async/await
- Install toast in your root view:
import SwiftUI
import Toasts
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.installToast(position: .bottom)
}
}
}
- Present a toast:
@Environment(\.presentToast) var presentToast
Button("Show Toast") {
let toast = ToastValue(
icon: Image(systemName: "bell"),
message: "You have a new notification."
)
presentToast(toast)
}
presentToast(
message: "Loading...",
task: {
// Handle loading task
return "Success"
},
onSuccess: { result in
ToastValue(icon: Image(systemName: "checkmark.circle"), message: result)
},
onFailure: { error in
ToastValue(icon: Image(systemName: "xmark.circle"), message: error.localizedDescription)
}
)

- Remove icon
let toast = ToastValue(
message: "Message only toast."
)
- Add button
let toast = ToastValue(
message: "Toast with action required.",
button: ToastButton(title: "Confirm", color: .green, action: {
// Handle button action
})
)
If you need to manually control the safe area insets for toasts (e.g., in a custom view hierarchy or when using multiple tabs), you can use the addToastSafeAreaObserver
modifier:
struct ContentView: View {
var body: some View {
TabView {
Tab1View()
Tab2View()
}
}
}
struct Tab1View: View {
var body: some View {
ScrollView {
// Your content here
}
.addToastSafeAreaObserver()
}
}
This modifier helps the toast system correctly detect and respond to safe area changes, which is particularly useful in complex view hierarchies or when using TabView.
- iOS 14.0+
- Swift 5.9+