Skip to content

sentryco/PromptManager

Repository files navigation

Tests codebeat badge

PromptManager

Alert and sheet tools for macOS and iOS

PromptManager is a versatile library designed to simplify the creation and management of alerts and sheets on macOS and iOS platforms. It provides a robust set of tools to handle various dialog types with ease, ensuring a consistent and user-friendly interface across different Apple devices.

Features

  • Cross-Platform Support: Works seamlessly on both macOS (v14 and above) and iOS (v17 and above).
  • SwiftUI Ready: Fully compatible with SwiftUI, offering a modern way to manage UI components.
  • Extensible: Easily extendable to include more complex alert types or custom interactions.

Presenting a Simple Alert

This example demonstrates how to present a simple alert with primary and secondary actions on both iOS and macOS platforms.

promptAlert(
    title: "Save Changes?",
    msg: "Do you want to save the changes you made?",
    primaryText: "Save",
    secondaryText: "Cancel",
    primaryHandler: { print("Changes saved") },
    secondaryHandler: { print("Cancelled") }
)

Presenting an Alert with Text Input

This example shows how to present an alert that includes text input fields, suitable for scenarios like login forms.

showTextInputAlert(
    title: "Login",
    message: "Please enter your username and password",
    primaryTextPlaceholder: "Username",
    secondaryTextPlaceholder: "Password",
    primaryButtonText: "Login",
    secondaryButtonText: "Cancel",
    isSecure: true,
    onComplete: { credentials in
        if let username = credentials?.primary, let password = credentials?.secondary {
            print("Username: \(username), Password: \(password)")
        } else {
            print("User cancelled login")
        }
    }
)

Presenting an Attributed Alert

This example demonstrates how to present an alert with attributed text, which allows for more stylized text presentations.

let attrTitle = NSAttributedString(string: "Important Update", attributes: [.foregroundColor: UIColor.red])
let attrMSG = NSAttributedString(string: "Please read the terms and conditions carefully.", attributes: [.foregroundColor: UIColor.blue])
UIAlertController.promptAlert(
    attrTitle: attrTitle,
    attrMSG: attrMSG,
    ok: { print("Accepted") },
    cancel: { print("Declined") },
    okTitle: "Accept",
    cancelTitle: "Decline"
)

Swift Package Manager

.package(url: "https://github.com/sentryco/PromptManager", branch: "main")

License

PromptManager is available under the MIT license. See the LICENSE file for more info.

About

Alert and sheet tools for macOS and iOS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages