{"id":2468,"url":"https://github.com/mshrwtnb/alrt","last_synced_at":"2026-02-23T17:32:23.835Z","repository":{"id":56900623,"uuid":"64518933","full_name":"mshrwtnb/ALRT","owner":"mshrwtnb","description":"An easier constructor for UIAlertController. Present an alert from anywhere.","archived":false,"fork":false,"pushed_at":"2020-12-20T05:49:32.000Z","size":125,"stargazers_count":96,"open_issues_count":0,"forks_count":11,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2024-12-01T23:41:30.438Z","etag":null,"topics":["alert","swift","uialertaction","uialertcontroller","uialertview"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mshrwtnb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-30T01:02:34.000Z","updated_at":"2023-12-22T18:33:36.000Z","dependencies_parsed_at":"2022-08-21T02:50:51.240Z","dependency_job_id":null,"html_url":"https://github.com/mshrwtnb/ALRT","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshrwtnb%2FALRT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshrwtnb%2FALRT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshrwtnb%2FALRT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshrwtnb%2FALRT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mshrwtnb","download_url":"https://codeload.github.com/mshrwtnb/ALRT/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228923680,"owners_count":17992566,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alert","swift","uialertaction","uialertcontroller","uialertview"],"created_at":"2024-01-05T20:16:14.480Z","updated_at":"2025-10-23T11:02:28.074Z","avatar_url":"https://github.com/mshrwtnb.png","language":"Swift","funding_links":[],"categories":["UI","Libs","UI [🔝](#readme)"],"sub_categories":["Alert \u0026 Action Sheet","UI"],"readme":"# ALRT\n\u003cimg src=\"https://app.bitrise.io/app/a83365a50419cead/status.svg?token=CsJmpuGa23wFB_6FYmeHVg\u0026branch=master\"\u003e\n\n\u003ca href=\"https://codecov.io/gh/mshrwtnb/ALRT\"\u003e\n  \u003cimg src=\"https://codecov.io/gh/mshrwtnb/ALRT/branch/master/graph/badge.svg\" /\u003e\n\u003c/a\u003e\n\n\u003cimg src=\"https://raw.githubusercontent.com/wiki/mshrwtnb/ALRT/logobanner.png\"\u003e\n\nAn easier constructor for UIAlertController. Present an alert from anywhere like this.\n\n```swift\nALRT.create(.alert, title: \"Alert?\").addOK().addCancel().show()\n```\n## Table of Contents\n- [Features](#features)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n- [License](#license)\n\n## Features\n* Chainable UIAlertController Setup Methods\n* Support `.alert` and `.actionSheet` UIAlertController.Style\n* Support `UITextfield` UIAlertAction(`.alert` only)\n* Returns `Result` whether an alert is successfully displayed. In other words, [Unit Testable](https://github.com/mshrwtnb/ALRT/blob/master/Demo/DemoTests/DemoTests.swift).\n\n## Requirements\n* Xcode 10.2+\n* Swift 5.0\n* iOS 9.0+\n\n## Installation\n### Carthage\n```\ngithub \"mshrwtnb/ALRT\" ~\u003e 1.3.7\n```\n### Cocoapods\n```\npod repo update\npod 'ALRT', '~\u003e 1.3.7'\n```\n\n## Usage\n### Basics\n#### `.alert`\n```swift\nimport ALRT\n\n// Instantiate an .alert-type UIAlertController with OK and Cancel actions. Finally, present the alert by calling `show()`.\nALRT.create(.alert, title: \"Title\", message: \"Message\").addOK().addCancel().show()\n```\n\n#### `.actionSheet`\n```swift\n// Instantiate an .actionSheet-type UIAlertController.\nALRT.create(.actionSheet, message: \"Action Sheet\")\n    .addAction(\"Option A\")\n    .addAction(\"Option B\")\n    .addDestructive(\"Destructive Option\")\n    .show() \n```\n\n### Action Types\nEach action comes with different `UIAlertAction.Style`.\n\n```swift\nALRT.create(.alert, title: \"Action Types?\")\n    .addAction(\"🏂\") // .default if not specified\n    .addOK() // .default\n    .addCancel(\"❌\") // .cancel\n    .addDestructive(\"💣\") // .destructive\n    .show()\n```\n\n### Custom Title\nOK and Cancel actions have default titles in English; \"OK\" and \"Cancel\".\nHere, we're overriding the titles in Japanese.\n\n```swift\nALRT.create(.alert, title: \"Actions In Japanese?\").addOK(\"オーケー\").addCancel(\"キャンセル\").show()\n```\n\n### Action Handling\nEach action has `handler` that is called when user taps the action.\nThe closure takes two parameters: `UIAlertAction` and `[UITextField]?`.\nThe former is self-explanatory.\nThe latter is present if text field(s) is/are added to the alert.\n\n```swift\nALRT.create(.alert, title: \"Action Handling\")\n    .addOK() { action, textFields in\n        print(\"\\(action.title!) tapped\")\n    }\n    .show()\n```\n\n### Result Handling\n`show()` has a completion handler that takes `Result`.\nYou can ensure if the alert was shown successfully or not. This is useful for unit tests.\n```swift\nALRT.create(.alert, title: \"Result Handling\")\n    .addOK()\n    .show() { result in\n        switch result {\n        case .success:\n            print(\"Alert is successfully shown\")\n        case .failure(let error):\n            print(\"Error occurred. \\(error.localizedDescription)\")\n        }\n    }\n```\n\n### TextField(s)\nTextfield(s) can be added to an alert in an use-case such as login.\n\n```swift\nenum TextFieldIdentifier: Int {\n    case username\n    case password\n}\n\nALRT.create(.alert, title: \"Enter your credentials\")\n    // Configure textfield\n    .addTextField { textfield in\n        textfield.placeholder = \"Username\"\n        textfield.tag = TextFieldIdentifier.username.rawValue\n    }\n    .addTextField() { textField in\n        textField.placeholder = \"Password\"\n        textField.isSecureTextEntry = true\n        textField.tag = TextFieldIdentifier.password.rawValue\n    }\n    // If an user selects \"Login\", textfields above are retrieved in the trailing closure. Distinguish one from another with a tag or identifier.\n    .addAction(\"Login\") { _, textfields in\n        for textField in textfields ?? [] {\n            if let identifier = TextFieldIdentifier(rawValue: textField.tag) {\n                switch identifier {\n                case .username:\n                    // Extract username\n                case .password:\n                    // Extract password\n                }\n            }\n        }\n    }\n    .addCancel()\n    .show()\n```\n\n### Changing source ViewController to present from\nAlthough ALRT can present an alert anywhere, you might want to specify a source view controller for some reason. This can be done easily by passing a view controller to `show()`.\n\n```swift\nALRT.create(.alert, title: \"Source?\")\n    .addOK()\n    .show(self) // self = source view controller\n```\n\n### Default Configuration\nSet default tintColor and titles for OK and Cancel buttons.\n\n```swift\nALRT.defaultConfiguration = .init(\n    tintColor: UIColor.blue,\n    okTitle: \"OK👍\",\n    cancelTitle: \"Cancel👎\"\n)\n```\n\n## License\nALRT is released under the MIT license. [See LICENSE](https://github.com/mshrwtnb/ALRT/blob/master/LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmshrwtnb%2Falrt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmshrwtnb%2Falrt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmshrwtnb%2Falrt/lists"}