SwiftyAlert
is a lightweight, multiplatform, easy-to-use swiftUI
package that for errors handling. Integrated with SwiftUI Environment
.
- macOS 12.0+
- iOS 15.0+
- macCatalyst 15.0+
- tvOS 15.0+
- watchOS 8.0+
- visionOS 1.0+
In an app project or framework, in Xcode:
-
Select the menu: File → Swift Packages → Add Package Dependency...
-
Enter this URL:
https://github.com/chocoford/SwiftyAlert
Or in a Swift Package, add it to the Package.swift dependencies:
let package = Package(
...
dependencies: [
.package(url: "https://github.com/chocoford/SwiftyAlert.git", from: "1.0.0"),
],
targets: [
.target(
...
dependencies: [
...
"SwiftyAlert"
],
...
)
]
)
import SwiftyAlert
for example, you can inject environments directly in YourApp.swift
@main
struct YourApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.swiftyAlert() // <-- inject environments here.
}
}
}
struct ContentView: View {
@Environment(\.alert) private var alert // <-- use with @Environment
var body: some View {
Button {
alert(title: "Alert") {
Button {
...
} label: {
Text("Alert action")
}
} message: {}
// or just use with error
do {...} catch {
alert(error)
}
} label: {
Text("Alert")
}
}
}
Also if your project has imported AlertToast
, you can use alertToast
in the same way!
import AlertToast
import SwiftyAlert
struct ContentView: View {
@Environment(\.alertToast) private var alertToast
var body: some View {
Button {
do {...} catch {
alertToast(error)
}
} label: {
Text("Toggle alertToast")
}
}
}
You can additionally apply .swiftyAlert(...)
to make alertToast displayed in sheet
or fullscreenCover
.
...
.sheet(isPresented: $showSheet) {
SheetView()
.swiftyAlert() // <-- inject for sheet view to display alertToast
}
Undefined symbols:...
JustReset Package Caches
and build again. The problem will be gone.
elai950 - AlertToast: Create Apple-like alerts & toasts using SwiftUI