Skip to content

3. Buttonless Alerts

Gabriel Theodoropoulos edited this page Apr 17, 2019 · 1 revision

Buttonless alerts

One of my favourites is the buttonless alert, which is great to show a message without having user interaction. A buttonless alert is actually a common alert controller, but with no action buttons. Presenting a buttonless alert with GTAlertCollection looks like that:

GTAlertCollection.shared.presentButtonlessAlert(withTitle: "Buttonless", message: "This is a buttonless alert!") { (success) in      
    if success {
        // The alert controller was presented...            
    }
}

Apart from the title and the message, there's a completion handler that contains a parameter called success. When that value is true, then the alert controller has been presented successfully, otherwise it has not. So, always check the value of that flag before taking any actions in the completion handler.

Buttonless alert

Since a buttonless alert has no action buttons to be tapped by the user, and therefore to be dismissed, it's our duty to remove it when it's appropriate to do so. Dismissing it takes the following:

GTAlertCollection.shared.dismissAlert(completion: nil)

If you want to know when the alert has been actually dismissed, don't pass nil in the completion above, instead implement the closure body:

GTAlertCollection.shared.dismissAlert(completion: {
    // Do something after the alert has been dismissed...
})
Clone this wiki locally