Skip to content

Quick Start

Rayhan Nabi edited this page Sep 2, 2019 · 5 revisions

A quick rundown of the basic usages of RNAlertController.

1. Simplest of them all

Swift

RNAlertController(title: "Message", message: "Server time out")
    .addOkButton()
    .present()

Objective-C

RNAlertController *alert = [[RNAlertController alloc] initWithTitle:@"Message" message:@"Server time out"];
[alert addOkButton];
[alert presentOn:nil completion:nil];

2. Two buttons

Swift

RNAlertController(title: "Message", message: "Server time out")
    .addOkButton()
    .addCancelButton()
    .present()

Objective-C

RNAlertController *alert = [[RNAlertController alloc] initWithTitle:@"Message" message:@"Server time out"];
[alert addOkButton];
[alert addCancelButton];
[alert presentOn:nil completion:nil];

3. Buttons with actions and styles

Swift

RNAlertController(title: "Message", message: "Server time out")
    .addButton(title: "OK", type: .default) { [weak self] in
        self?.doSomething()
    }
    .addButton(title: "Cancel", type: .cancel, action: nil)
    .present()

Objective-C

RNAlertController *alert = [[RNAlertController alloc] initWithTitle:@"Message" message:@"Server time out"];
[alert addButtonWithTitle:@"OK", type: AlertButtonTypeDefault action:^{
    [self doSomething];
}];
[alert addButtonWithTitle:@"Cancel", type: AlertButtonTypeCancel action:nil];
[alert presentOn:nil completion:nil];

For more usage and customization see related wikis.

Did you

Found bugs?

Create an issue.

Need Something?

Create a feature request.

Need Anything else?

For any queries, send me a message at Telegram: @rayhannabi

Clone this wiki locally