SwiftyAlert

1.0.4

a lightweight, multiplatform, easy-to-use package that for swiftUI errors handling.
chocoford/SwiftyAlert

What's New

v1.0.4

2024-03-06T08:05:50Z

Swifty Alert

GitHub License X (formerly Twitter) Follow

SwiftyAlert is a lightweight, multiplatform, easy-to-use swiftUI package that for errors handling. Integrated with SwiftUI Environment.

Platforms

  • macOS 12.0+
  • iOS 15.0+
  • macCatalyst 15.0+
  • tvOS 15.0+
  • watchOS 8.0+
  • visionOS 1.0+

Installation

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"
            ],
            ...
        )
    ]
)

Usage

Import package

import SwiftyAlert

Inject environments somewhere first

for example, you can inject environments directly in YourApp.swift

@main
struct YourApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .swiftyAlert() // <-- inject environments here.
        }
    }
}

Use with @Environment

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")
        }
    }
}

Use with AlertToast

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")
    }
  }
}

Trouble shooting

  • Undefined symbols:... Just Reset Package Caches and build again. The problem will be gone.

Acknowledgment

elai950 - AlertToast: Create Apple-like alerts & toasts using SwiftUI

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Apr 26 2024 19:32:22 GMT-0900 (Hawaii-Aleutian Daylight Time)