https://github.com/phimage/alertcontroller
An NSViewController to display an alert message to the user. This class replaces the NSAlert class.
https://github.com/phimage/alertcontroller
Last synced: 6 months ago
JSON representation
An NSViewController to display an alert message to the user. This class replaces the NSAlert class.
- Host: GitHub
- URL: https://github.com/phimage/alertcontroller
- Owner: phimage
- License: mit
- Created: 2016-10-28T15:34:24.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-06-01T08:42:16.000Z (9 months ago)
- Last Synced: 2025-08-13T03:07:56.651Z (6 months ago)
- Language: Swift
- Homepage:
- Size: 4.19 MB
- Stars: 8
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AlertController
[](http://mit-license.org)
[](https://developer.apple.com/resources/)
[](https://developer.apple.com/swift)
[](https://github.com/phimage/AlertController/issues)
[](http://cocoadocs.org/docsets/NSAlertController/)
A `NSViewController` to display an alert message to the user.
This class replaces the `NSAlert` class and is inspired from `UIAlertController`.
After configuring the alert controller with the actions and style you want, present it using `presentViewControllerAsSheet`.
```swift
let controller = AlertController(title: "Alert title", message: "An alert message", preferredStyle: .warning)
parentVC.presentViewControllerAsSheet(controller)
```
## Usage
### Add a simple dismiss action
```swift
controller.add(action: AlertAction.dismiss(for: controller, title: "Ok"))
```
### Add custom action
```swift
controller.add(action: AlertAction(title: "Report...") { action in
NSWorkspace.shared().open(URL(string: "https://github.com/phimage/AlertController/issues")!)
})
```
### Choose a style
```swift
controller.addAction(title: "", style: .helpButton) { action in
// show error help
}
```
### Customize buttons bar
```swift
controller.buttonsBar.color = NSColor.red
controller.buttonsBar.buttonSpace = 8
```

## Todo
- More customization
- align buttons left or right
- automatic helpButton on left
- Maybe input text fields
## Installation
### Using CocoaPods ##
[CocoaPods](https://cocoapods.org/) is a centralized dependency manager for
Objective-C and Swift. Go [here](https://guides.cocoapods.org/using/index.html)
to learn more.
1. Add the project to your [Podfile](https://guides.cocoapods.org/using/the-podfile.html).
```ruby
use_frameworks!
pod 'NSAlertController'
```
2. Run `pod install` and open the `.xcworkspace` file to launch Xcode.
### Using Carthage ##
```ruby
github 'phimage/AlertController'
```