diff --git a/CHANGELOG.md b/CHANGELOG.md index 829e530..52d8095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Next +## 3.2.0 +- Added support to display a checkmark with `isChecked` + ## 3.1.0 - Updated to Swift 5.1 diff --git a/Example/ImageAlertAction/ViewController.swift b/Example/ImageAlertAction/ViewController.swift index 8d62611..ef274fd 100644 --- a/Example/ImageAlertAction/ViewController.swift +++ b/Example/ImageAlertAction/ViewController.swift @@ -15,6 +15,9 @@ class ViewController: UIViewController { let settings = UIAlertAction(title: "Settings", image: #imageLiteral(resourceName: "settings"), style: .default) alertController.addAction(settings) + + let selectedSettings = UIAlertAction(title: "Checked Settings", image: #imageLiteral(resourceName: "settings"), isChecked: true, style: .default) + alertController.addAction(selectedSettings) let cancel = UIAlertAction(title: "Cancel", style: .cancel) alertController.addAction(cancel) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 03fe1f8..77d533f 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - ImageAlertAction (3.1.0) + - ImageAlertAction (3.2.0) DEPENDENCIES: - ImageAlertAction (from `../`) @@ -9,7 +9,7 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - ImageAlertAction: 2f4d6ecd9d4896eb4bb959f9d1c8a1101d6805f4 + ImageAlertAction: 5556758a632c531172c5b2afcc4a25417df9f5a2 PODFILE CHECKSUM: 2861c5c31891940484aaf82fd18a1725282b6061 diff --git a/Example/Pods/Local Podspecs/ImageAlertAction.podspec.json b/Example/Pods/Local Podspecs/ImageAlertAction.podspec.json index c404ec6..02444a7 100644 --- a/Example/Pods/Local Podspecs/ImageAlertAction.podspec.json +++ b/Example/Pods/Local Podspecs/ImageAlertAction.podspec.json @@ -1,6 +1,6 @@ { "name": "ImageAlertAction", - "version": "3.1.0", + "version": "3.2.0", "summary": "Image support for UIAlertAction", "description": "ImageAlertAction adds image support to UIAlertAction.\nUse this to visually convey an action's purpose.", "homepage": "https://github.com/BasThomas/ImageAlertAction", @@ -17,7 +17,7 @@ }, "source": { "git": "https://github.com/BasThomas/ImageAlertAction.git", - "tag": "3.1.0" + "tag": "3.2.0" }, "social_media_url": "https://twitter.com/basthomas", "platforms": { diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock index 03fe1f8..77d533f 100644 --- a/Example/Pods/Manifest.lock +++ b/Example/Pods/Manifest.lock @@ -1,5 +1,5 @@ PODS: - - ImageAlertAction (3.1.0) + - ImageAlertAction (3.2.0) DEPENDENCIES: - ImageAlertAction (from `../`) @@ -9,7 +9,7 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - ImageAlertAction: 2f4d6ecd9d4896eb4bb959f9d1c8a1101d6805f4 + ImageAlertAction: 5556758a632c531172c5b2afcc4a25417df9f5a2 PODFILE CHECKSUM: 2861c5c31891940484aaf82fd18a1725282b6061 diff --git a/Example/Pods/Target Support Files/ImageAlertAction/ImageAlertAction-Info.plist b/Example/Pods/Target Support Files/ImageAlertAction/ImageAlertAction-Info.plist index 90db36a..9ae03a0 100644 --- a/Example/Pods/Target Support Files/ImageAlertAction/ImageAlertAction-Info.plist +++ b/Example/Pods/Target Support Files/ImageAlertAction/ImageAlertAction-Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 3.1.0 + 3.2.0 CFBundleSignature ???? CFBundleVersion diff --git a/Example/Tests/Tests.swift b/Example/Tests/Tests.swift index d1e40ab..7f0cbc4 100644 --- a/Example/Tests/Tests.swift +++ b/Example/Tests/Tests.swift @@ -6,4 +6,14 @@ class Tests: XCTestCase { let action = UIAlertAction(title: "Hello world!", image: #imageLiteral(resourceName: "settings"), style: .cancel) XCTAssertNotNil(action.image) } + + func testCheckmarkIsCorrectlySet() { + let action = UIAlertAction(title: "Hello world!", image: #imageLiteral(resourceName: "settings"), isChecked: true, style: .cancel) + XCTAssertTrue(action.isChecked) + } + + func testCheckmarkIsNotSet() { + let action = UIAlertAction(title: "Hello world!", image: #imageLiteral(resourceName: "settings"), style: .cancel) + XCTAssertFalse(action.isChecked) + } } diff --git a/ImageAlertAction.podspec b/ImageAlertAction.podspec index 9939aaf..b2bd5ae 100644 --- a/ImageAlertAction.podspec +++ b/ImageAlertAction.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'ImageAlertAction' - s.version = '3.1.0' + s.version = '3.2.0' s.summary = 'Image support for UIAlertAction' s.description = <<-DESC ImageAlertAction adds image support to UIAlertAction. diff --git a/ImageAlertAction/Classes/UIAlertAction+Image.swift b/ImageAlertAction/Classes/UIAlertAction+Image.swift index e3348c9..021ae1e 100644 --- a/ImageAlertAction/Classes/UIAlertAction+Image.swift +++ b/ImageAlertAction/Classes/UIAlertAction+Image.swift @@ -11,6 +11,7 @@ import UIKit extension UIAlertAction { private var imageKey: String { "image" } + private var isCheckedKey: String { "checked" } /// Create and return an action with the specified title and behavior. /// @@ -24,6 +25,7 @@ extension UIAlertAction { /// may be used with [UIAlertAction.Style.cancel](https://developer.apple.com/documentation/uikit/uialertaction/style/cancel). /// - parameter image: An image to display on the left side of the button. /// Use this to visually convey the action's purpose. + /// - parameter isChecked: A boolean that will be used to determine if a check mark should be displayed on the right side of the title /// - parameter style: Additional styling information to apply to the button. /// Use the style information to convey the type of action that is performed by the button. /// For a list of possible values, see the constants in @@ -36,13 +38,17 @@ extension UIAlertAction { public convenience init( title: String? = nil, image: UIImage, + isChecked: Bool = false, style: UIAlertAction.Style, handler: ((UIAlertAction) -> Void)? = nil ) { self.init(title: title, style: style, handler: handler) setValue(image, forKey: imageKey) + setValue(isChecked, forKey: isCheckedKey) } /// The image of the action's button. public var image: UIImage? { value(forKey: imageKey) as? UIImage } + + public var isChecked: Bool { value(forKey: isCheckedKey) as? Bool ?? false } } diff --git a/README.md b/README.md index d7e0fef..d537d48 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,20 @@ let settings = UIAlertAction( settings.image // returns an optional UIImage ``` +#### Adding a checkmark + +You can also show a check mark on actions via `isChecked` + +```swift +let settings = UIAlertAction( + title: "Settings", + image: #imageLiteral(resourceName: "settings"), + isChecked: true + style: .default +) +settings.isChecked // returns a Bool +``` + ### Presenting the `UIAlertController` To present a `UIAlertController` containing the `UIAlertAction`, nothing changes.