Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/enebin/alertstate
Abstract alerts for your SwiftUI project
https://github.com/enebin/alertstate
ios swift swift-package-manager swiftui
Last synced: 6 days ago
JSON representation
Abstract alerts for your SwiftUI project
- Host: GitHub
- URL: https://github.com/enebin/alertstate
- Owner: enebin
- License: mit
- Created: 2022-08-31T06:17:24.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-12T13:03:32.000Z (over 2 years ago)
- Last Synced: 2024-10-31T14:07:28.967Z (about 2 months ago)
- Topics: ios, swift, swift-package-manager, swiftui
- Language: Swift
- Homepage: https://enebin.medium.com/swiftui-lets-manage-alert-more-easily-with-protocol-bcf5433a5451
- Size: 17.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AlertState
Manage `Alert`s in one place!## Overview
| Normal alert | Multi button alert |
|----------|----------|
| | |
## Features
### Super easy to use
- You only need 2 lines to show alert in `View`s. No needs to write extra variables like `isPresented`!### Manage everything in one place
- It helps you managing the alert windows with more organized way.### 100% compatible with native features
- You can use button role(`cancel`, `default`, `destructive`) in the same way you did in SwiftUI
- It's compatible with any version of iOS.## Requirements
- iOS 13
- Swift 5.5
- Xcode 12## How to install
### Swift Package Manager
It only supprots SPM yet.1. In Xcode, open your project and navigate to File → Add Packages.
2. Copy and past the repository's URL.
```
https://github.com/enebin/AlertState
```
3. Choose a version you want and add it to your project.## Usage
After [some setup](https://github.com/enebin/AlertState/wiki/How-to-setup), You can use `AlertState` like this:
``` Swift
import SwiftUI
import AlertStatestruct ContentView: View {
// @State var alertState: SystemAlert?
// or...
@AlertState var alertStatevar body: some View {
VStack(spacing: 30) {
Button(action: {
alertState = .warning
}) {
Text("Warning")
}Button(action: {
alertState = .errorHappend(/* SomeError */, dismissAction: { /* some dismiss action */ })
}) {
Text("Error")
}Button(action: {
alertState = .retry(primaryAction: { /* some actions */ }, secondaryAction: { /* some actions */ })
}) {
Text("Retry")
}
}
.showAlert(with: $alertState)
}
}
```## Example
For more informations, check [the example projects](https://github.com/enebin/AlertState/tree/main/Examples).