Skip to content
/ Bugle Public

Helper for displaying alerts without writing boilerplate code.

License

Notifications You must be signed in to change notification settings

yellowme/Bugle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bugle

Version License Platform

Bugle, is a helper for displaying alerts without writing boilerplate code.

Installation

CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To give Bugle a try with an example project, run the following command:

$ pod try Bugle

To integrate Bugle into your Xcode project, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '11.0'
use_frameworks!

target 'MyApp' do
    pod 'Bugle', '~> 2.0'
end

Then, run the following command:

$ pod install

Simple usage

At your view controller use:

let alert = UIAlertController(style: .alert, title: "Bugle", message: "This is an alert with title")
alert.addAction(title: "OK", style: .cancel)
alert.show()

Customize

Since this version is depending directly to UIAlertController extensions you could create a file with your own extension methods:

extension String {
    // NOTE: Maybe you could use localization approaches here.
    static let defaultAlertTitle = "Bugle"
    static let defaultAlertActionLabel = "Understood"
}

// MARK: - Initializers
extension UIAlertController {
    /// Create new alert view controller.
    ///
    /// - Parameters:
    ///   - message: alert controller's message (default is nil).
    ///   - tintColor: alert controller's tint color (default is nil)
    convenience init(message: String? = nil, tintColor: UIColor? = nil) {
        self.init(
            title: String.defaultAlertTitle,
            message: message,
            preferredStyle: .alert
        )
    }
}

extension UIAlertController {
    /// Displays an alert view by adding the default action in order to be able to dismiss it.
    func play() {
        self.addAction(UIAlertAction(title: String.defaultAlertActionLabel, style: .default, handler: nil))
        self.show()
    }
}

Then:

let alert = UIAlertController(message: "Hello World!")
alert.play()

See a full version here

Contributors

License

Bugle is released under the MIT license. See LICENSE for details.

About

Helper for displaying alerts without writing boilerplate code.

Resources

License

Stars

Watchers

Forks

Packages

No packages published