{"id":2425,"url":"https://github.com/Lightningkite/LKAlertController","last_synced_at":"2025-08-02T23:33:32.084Z","repository":{"id":49710539,"uuid":"39091475","full_name":"lightningkite/LKAlertController","owner":"lightningkite","description":"An easy to use UIAlertController builder for swift","archived":false,"fork":false,"pushed_at":"2021-06-10T17:29:51.000Z","size":176,"stargazers_count":98,"open_issues_count":2,"forks_count":21,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-12-01T05:17:31.489Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/lightningkite.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2015-07-14T17:58:01.000Z","updated_at":"2024-06-03T22:30:17.000Z","dependencies_parsed_at":"2022-08-25T06:00:22.279Z","dependency_job_id":null,"html_url":"https://github.com/lightningkite/LKAlertController","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightningkite%2FLKAlertController","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightningkite%2FLKAlertController/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightningkite%2FLKAlertController/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightningkite%2FLKAlertController/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lightningkite","download_url":"https://codeload.github.com/lightningkite/LKAlertController/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228503211,"owners_count":17930539,"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":[],"created_at":"2024-01-05T20:16:13.457Z","updated_at":"2024-12-06T17:31:05.239Z","avatar_url":"https://github.com/lightningkite.png","language":"Swift","funding_links":[],"categories":["UI"],"sub_categories":["Alert \u0026 Action Sheet","Other free courses"],"readme":"# LKAlertController\n\n[![Circle CI](https://circleci.com/gh/lightningkite/LKAlertController/tree/master.svg?style=svg)](https://circleci.com/gh/lightningkite/LKAlertController)\n[![Version](https://img.shields.io/cocoapods/v/LKAlertController.svg?style=flat)](http://cocoapods.org/pods/LKAlertController)\n[![License](https://img.shields.io/cocoapods/l/LKAlertController.svg?style=flat)](http://cocoapods.org/pods/LKAlertController)\n[![Platform](https://img.shields.io/cocoapods/p/LKAlertController.svg?style=flat)](http://cocoapods.org/pods/LKAlertController)\n\nAn easy to use UIAlertController builder for swift\n\n## Features\n* Short and simple syntax for creating both Alerts and ActionSheets from UIAlertController\n* String together methods to build more complex alerts and action sheets\n\n## Basic Usage\n\n### Alert\n``` Swift\nAlert(title: \"Title\", message: \"Message\")\n\t.addAction(\"Cancel\")\n\t.addAction(\"Delete\", style: .Destructive, handler: { _ in\n\t\t//Delete the object\n\t}).show()\n```\n\n### Action Sheet\n``` Swift\nActionSheet(title: \"Title\", message: \"Message\")\n\t.addAction(\"Cancel\")\n\t.addAction(\"Delete\", style: .Destructive, handler: { _ in\n\t\t//Delete the object\n\t}).show()\n```\n\n## Detailed Usage\n\nThere are two seperate classes for creating `UIAlertControllers`, `Alert`, and `ActionSheet`. These are used to simplify the creation of the controller. Both can be initialized with or without both a title and message.\n\n``` Swift\nAlert()\nActionSheet()\n\nAlert(title: \"My title\")\nActionSheet(title: \"My title\")\n\nAlert(message: \"My message\")\nActionSheet(message: \"My message\")\n\nAlert(title: \"My title\", message: \"My message\")\nActionSheet(title: \"My title\", message: \"My message\")\n```\n\nAdd various actions to the controller using `addAction`. By default the button will be styled `Cancel`, but this can be configured on a per button basis, along with the handler that is called if the button is clicked. The possible styles are `Cancel`, `Default`, and `Destructive`. These methods can be strung together to add more buttons to the controller.\n\n``` Swift\nActionSheet()\n\t.addAction(\"Cancel\")\n\t.addAction(\"Save\", style: .Default) {\n\t\tsaveTheObject()\n\t}\n\t.addAction(\"Delete\", style: Destructive) {\n\t\tdeleteTheObject()\n\t}\n```\n\nThe controller can be presented by calling `show()`. It will be animated by default.\n\n``` Swift\nAlert()\n\t.addAction(\"Okay\")\n\t.show()\n\t\nActionSheet()\n\t.addAction(\"Delete\", style: .Destructive) {\n\t\tdelete()\n\t}\n\t.addAction(\"Cancel\")\n\t.show(animated: true) {\n\t\tcontrollerWasPresented()\n\t}\n```\n\n### Alert Specific Configuration\n\nThere is a shortcut on alerts to show with an okay button: `showOkay`\n\n``` Swift\nAlert(title: \"Stuff has happened\").showOkay()\n```\n\nYou can also add your own shortcut show method. The following adds a `showNevermind` button that adds a `Nevermind` button and shows the alert.\n\n``` Swift\nextension Alert {\n\t///Shortcut method for adding a nevermind button and showing the alert\n\tpublic func showNevermind() {\n\t\taddAction(\"Nevermind\", style: .Cancel, preferredAction: false, handler: nil)\n\t\tshow()\n\t}\n}\n```\n\nText fields can also be added to alerts. To add a text field, initialize a text field first, and configure it, then pass it in with the alert. Note that text fields must be initialized as `var` rather than `let`\n\n``` Swift\nvar textField = UITextField()\ntextField.placeholder = \"Password\"\ntextField.secureTextEntry = true\n\nAlert().addTextfield(\u0026textField).showOkay()\n```\n\nYou can also configure the `preferredAction` property on an alert. This will highlight the text of the action, and pressing the return key on a physical keyboard will trigger this action.\n\n``` Swift\nAlert()\n\t.addAction(\"Okay\", style: .Default, preferredAction: true)\n\t.show()\n```\n\n### ActionSheet Specific Configuration\n\nIf presenting on iPad, ActionSheets need to be configured with where it is presenting from. This is done by using the `setBarButtonItem` or `setPresentingSource` function. Note that this has no effect on iPhone, so it is safe, and recommended, to call this method if your app supports both iPad and iPhone.\n\n``` Swift\nActionSheet()\n\t.addAction(\"Delete\", style: .Destructive) {\n\t\tdelete()\n\t}\n\t.addAction(\"Cancel\")\n\t.setBarButtonItem(navigationController.rightBarButtonItem)\n\t.show(animated: true) {\n\t\tcontrollerWasPresented()\n\t}\n\t\nActionSheet()\n\t.addAction(\"Delete\", style: .Destructive) {\n\t\tdelete()\n\t}\n\t.addAction(\"Cancel\")\n\t.setPresentingSource(buttonThatWasPressed)\n\t.show(animated: true) {\n\t\tcontrollerWasPresented()\n\t}\n```\n\n##Testing\n\nYou can add an override for the `show` method to make it easy to add unit tests for your alerts.\n\n``` Swift\nfunc testDeleteOpensConfirmationAlert() {\n\tlet expectation = expectationWithDescription(\"Show override\")\n\n\tLKAlertController.overrideShowForTesting { (style, title, message, actions, fields) -\u003e Void in \n\t\t\n\t\tXCTAssertEquals(title, \"Are you sure you want to delete?\", \"Alert title was incorrect\")\n\t\t\n\t\texpectation.fulfill()\n\t}\n\t\n\tmodel.delete()\n\t\n\t//If the override is never called, and the expectation is not fulfilled, the test will fail\n\twaitForExpectations(0.5, handler: nil)\n}\n```\n\nThis will allow you to test the controller was presented as well as the title, message, actions and fields of the alert or action sheet.\n\n## Installation\n\nLKAlertController is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"LKAlertController\"\n```\n\n### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate LKAlertController into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```ogdl\ngithub \"lightningkite/LKAlertController\"\n```\n\nRun `carthage update` to build the framework and drag the built `LKAlertController.framework` into your Xcode project.\n\n\n## Issues Questions and Contributing\nHave an issue, or want to request a feature? Create an issue in github.\n\nWant to contribute? Add yourself to the authors list, and create a pull request.\n\n## Author\n\nErik Sargent, [erik@lightningkite.com](mailto:erik@lightningkite.com)\n\n## License\n\nLKAlertController is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLightningkite%2FLKAlertController","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLightningkite%2FLKAlertController","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLightningkite%2FLKAlertController/lists"}