From d63b9860b7c1db4fde3313109e3f5736f9b432ef Mon Sep 17 00:00:00 2001 From: sgr-ksmt Date: Fri, 5 Jul 2019 17:47:41 +0900 Subject: [PATCH 1/4] added short handler. --- Sources/ActionSheet.swift | 10 +++++++++- Sources/Alert.swift | 15 +++++++++++++++ Sources/AlertType.swift | 11 ++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Sources/ActionSheet.swift b/Sources/ActionSheet.swift index e355921..c911a49 100644 --- a/Sources/ActionSheet.swift +++ b/Sources/ActionSheet.swift @@ -11,7 +11,6 @@ import Foundation extension Alertift { /// ActionSheet final public class ActionSheet: AlertType, _AlertType { - public typealias Handler = (UIAlertAction, Int) -> Void var _alertController: InnerAlertController! @@ -39,6 +38,11 @@ extension Alertift { return self.action(action, image: nil, handler: handler) } + public func action(_ action: Alertift.Action, handler: ShortHandler?) -> Self { + return self.action(action) { _, _ in handler?() } + } + + /// Add action to alertController public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, handler: Handler? = nil) -> Self { let alertAction = buildAlertAction(action, handler: @@ -52,6 +56,10 @@ extension Alertift { _alertController.addAction(alertAction) return self } + + public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, handler: ShortHandler? = nil) -> Self { + return self.action(action, image: image, renderingMode: renderingMode) { _, _ in handler?() } + } /// Add sourceView and sourceRect to **popoverPresentationController**. /// diff --git a/Sources/Alert.swift b/Sources/Alert.swift index b664f03..0956c0e 100644 --- a/Sources/Alert.swift +++ b/Sources/Alert.swift @@ -49,6 +49,9 @@ extension Alertift { return self.action(action, isPreferred: false, handler: handler) } + public func action(_ action: Alertift.Action, handler: ShortHandler? = nil) -> Self { + return self.action(action) { _, _, _ in handler?() } + } /// Add action to Alert /// /// - Parameters: @@ -60,6 +63,10 @@ extension Alertift { return self.action(action, image: nil, isPreferred: isPreferred, handler: handler) } + public func action(_ action: Alertift.Action, isPreferred: Bool, handler: ShortHandler? = nil) -> Self { + return self.action(action, image: nil, isPreferred: isPreferred) { _, _, _ in handler?() } + } + /// Add action to Alert /// /// - Parameters: @@ -72,6 +79,10 @@ extension Alertift { return self.action(action, image: image, renderingMode: renderingMode, isPreferred: false, handler: handler) } + public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, handler: ShortHandler? = nil) -> Self { + return self.action(action, image: image, renderingMode: renderingMode, isPreferred: false) { _, _, _ in handler?() } + } + /// Add action to Alert /// /// - Parameters: @@ -95,6 +106,10 @@ extension Alertift { return self } + public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, isPreferred: Bool, handler: ShortHandler? = nil) -> Self { + return self.action(action, image: image, renderingMode: renderingMode, isPreferred: isPreferred) { _, _, _ in handler?() } + } + /// Add text field to alertController /// /// - Parameter handler: Define handler if you want to customize UITextField. Default is nil. diff --git a/Sources/AlertType.swift b/Sources/AlertType.swift index 8914115..1ea6226 100644 --- a/Sources/AlertType.swift +++ b/Sources/AlertType.swift @@ -29,6 +29,7 @@ extension _AlertType where Self: AlertType { /// AlertType protocol public protocol AlertType: class { associatedtype Handler + typealias ShortHandler = () -> Void /// Add action to Alert /// @@ -37,7 +38,15 @@ public protocol AlertType: class { /// - handler: The block to execute after this action performed. /// - Returns: Myself func action(_ action: Alertift.Action, handler: Handler?) -> Self - + + /// Add action to Alert + /// + /// - Parameters: + /// - action: Alert action. + /// - handler: The block to execute after this action performed. + /// - Returns: Myself + func action(_ action: Alertift.Action, handler: ShortHandler?) -> Self + /// UIAlertController var alertController: UIAlertController { get } /// default background color of Alert(ActionSheet). From 9b31fe52f4d4920ed682287c6ff86668cbe56160 Mon Sep 17 00:00:00 2001 From: sgr-ksmt Date: Fri, 5 Jul 2019 17:49:32 +0900 Subject: [PATCH 2/4] fixed ambigeous issue. --- Sources/ActionSheet.swift | 6 +++--- Sources/Alert.swift | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/ActionSheet.swift b/Sources/ActionSheet.swift index c911a49..a707a36 100644 --- a/Sources/ActionSheet.swift +++ b/Sources/ActionSheet.swift @@ -34,17 +34,17 @@ extension Alertift { } /// Add action to alertController - public func action(_ action: Alertift.Action, handler: Handler? = nil) -> Self { + public func action(_ action: Alertift.Action, handler: Handler?) -> Self { return self.action(action, image: nil, handler: handler) } - public func action(_ action: Alertift.Action, handler: ShortHandler?) -> Self { + public func action(_ action: Alertift.Action, handler: ShortHandler? = nil) -> Self { return self.action(action) { _, _ in handler?() } } /// Add action to alertController - public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, handler: Handler? = nil) -> Self { + public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, handler: Handler?) -> Self { let alertAction = buildAlertAction(action, handler: merge(_alertController.actionHandler, handler ?? { (_, _) in }) ) diff --git a/Sources/Alert.swift b/Sources/Alert.swift index 0956c0e..b649216 100644 --- a/Sources/Alert.swift +++ b/Sources/Alert.swift @@ -45,7 +45,7 @@ extension Alertift { buildAlertControlelr(title: title, message: message, style: .alert) } - public func action(_ action: Alertift.Action, handler: Handler? = nil) -> Self { + public func action(_ action: Alertift.Action, handler: Handler?) -> Self { return self.action(action, isPreferred: false, handler: handler) } @@ -59,7 +59,7 @@ extension Alertift { /// - isPreferred: If you want to change this action to preferredAction, set true. Default is false. /// - handler: The block to execute after this action performed. /// - Returns: Myself - public func action(_ action: Alertift.Action, isPreferred: Bool, handler: Handler? = nil) -> Self { + public func action(_ action: Alertift.Action, isPreferred: Bool, handler: Handler?) -> Self { return self.action(action, image: nil, isPreferred: isPreferred, handler: handler) } @@ -75,7 +75,7 @@ extension Alertift { /// - renderMode: Render mode for alert action image. Default is `.automatic` /// - handler: The block to execute after this action performed. /// - Returns: Myself - public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, handler: Handler? = nil) -> Self { + public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, handler: Handler?) -> Self { return self.action(action, image: image, renderingMode: renderingMode, isPreferred: false, handler: handler) } @@ -92,7 +92,7 @@ extension Alertift { /// - isPreferred: If you want to change this action to preferredAction, set true. Default is false. /// - handler: The block to execute after this action performed. /// - Returns: Myself - public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, isPreferred: Bool, handler: Handler? = nil) -> Self { + public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, isPreferred: Bool, handler: Handler?) -> Self { let alertAction = buildAlertAction( action, handler: merge(_alertController.actionWithTextFieldsHandler, handler ?? { (_, _, _)in }) From 51ed01725e7fefd9e65f7e0760870a841898da3e Mon Sep 17 00:00:00 2001 From: sgr-ksmt Date: Fri, 5 Jul 2019 17:50:16 +0900 Subject: [PATCH 3/4] fixed demo project. --- Demo/Demo/ViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Demo/Demo/ViewController.swift b/Demo/Demo/ViewController.swift index 853c7eb..5006846 100644 --- a/Demo/Demo/ViewController.swift +++ b/Demo/Demo/ViewController.swift @@ -75,12 +75,12 @@ class ViewController: UIViewController { private func showYesOrNoAlert() { Alertift.alert(title: "Sample 2",message: "Do you like 🍣?") - .action(.default("Yes"), isPreferred: true) { (_, _, _) in + .action(.default("Yes"), isPreferred: true) { Alertift.alert(message: "🍣🍣🍣") .action(.default("Close")) .show() } - .action(.cancel("No")) { (_, _, _) in + .action(.cancel("No")) { Alertift.alert(message: "😂😂😂") .action(.destructive("Close")) .show() From ca228a6386bb420674e1d31f79ae679b1cb289f5 Mon Sep 17 00:00:00 2001 From: sgr-ksmt Date: Fri, 5 Jul 2019 17:52:14 +0900 Subject: [PATCH 4/4] fixed readme, how_to_use. --- Alertift.podspec | 2 +- Documents/how_to_use.md | 2 +- README.md | 7 ++----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Alertift.podspec b/Alertift.podspec index eaddc01..f9bd3a4 100644 --- a/Alertift.podspec +++ b/Alertift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Alertift" - s.version = "4.1" + s.version = "4.1.1" s.summary = "UIAlertControlelr wrapper for Swift." s.homepage = "https://github.com/sgr-ksmt/Alertift" # s.screenshots = "" diff --git a/Documents/how_to_use.md b/Documents/how_to_use.md index 73fa644..3219c88 100644 --- a/Documents/how_to_use.md +++ b/Documents/how_to_use.md @@ -14,7 +14,7 @@ Alertift.alert(title: "Sample 1", message: "Simple alert!") ```swift Alertift.alert(title: "Confirm", message: "Delete this post?") - .action(.destructive("Delete")) { _, _, _ in + .action(.destructive("Delete")) { // delete post } .action(.cancel("Cancel")) diff --git a/README.md b/README.md index 18d87ac..8c3e902 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ Alertift.alert(title: "Alertift", message: "Alertift is swifty, modern, and awes ## Requirements - iOS 9.0+ -- Xcode 8.1+ -- Swift 3.0+ +- Xcode 10+ +- Swift 5.0+ ## Installation @@ -81,9 +81,6 @@ and run `pod install` ### Manually Install Download all `*.swift` files and put your project. -## Change log -Change log is [here](https://github.com/sgr-ksmt/Alertift/blob/master/CHANGELOG.md). - ## Communication - If you found a bug, open an issue. - If you have a feature request, open an issue.