Skip to content

Commit

Permalink
Adding @discardableResult where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Sargent committed Oct 21, 2016
1 parent 5dfc964 commit 66d3e60
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Pod/Classes/LKAlertController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class LKAlertController {
- parameter style: Style of the button (.Default, .Cancel, .Destructive)
- parameter handler: Closure to call when the button is pressed
*/
@discardableResult
public func addAction(_ title: String, style: UIAlertActionStyle, handler: actionHandler? = nil) -> LKAlertController {
addAction(title, style: style, preferredAction: false, handler: handler)

Expand All @@ -92,6 +93,7 @@ public class LKAlertController {
- parameter preferredAction: Whether or not this action is the default action when return is pressed on a hardware keyboard
- parameter handler: Closure to call when the button is pressed
*/
@discardableResult
internal func addAction(_ title: String, style: UIAlertActionStyle, preferredAction: Bool = false, handler: actionHandler? = nil) -> LKAlertController {
var action: UIAlertAction
if let handler = handler {
Expand All @@ -112,18 +114,21 @@ public class LKAlertController {
}

///Set the view controller to present the alert in. By default this is the top controller in the window.
@discardableResult
public func presentIn(_ source: UIViewController) -> LKAlertController {
presentationSource = source
return self
}

///Delay the presentation of the controller.
@discardableResult
public func delay(_ time: TimeInterval) -> LKAlertController {
delayTime = time
return self
}

///Present in the view
@discardableResult
public func show() {
show(animated: true, completion: nil)
}
Expand All @@ -133,6 +138,7 @@ public class LKAlertController {
- parameter animated: Whether to animate into the view or not
*/
@discardableResult
public func show(animated: Bool) {
show(animated: animated, completion: nil)
}
Expand All @@ -143,6 +149,7 @@ public class LKAlertController {
- parameter animated: Whether to animate into the view or not
- parameter completion: Closure to call when the button is pressed
*/
@discardableResult
public func show(animated: Bool, completion: (() -> Void)?) {
//If a delay time has been set, delay the presentation of the alert by the delayTime
if let time = delayTime {
Expand Down Expand Up @@ -193,11 +200,13 @@ public class LKAlertController {
}

///Returns the instance of the UIAlertController
@discardableResult
public func getAlertController() -> UIAlertController {
return alertController
}

///Override the show function with a closure for using with your unit tests
@discardableResult
public class func overrideShowForTesting(_ callback: ((_ style: UIAlertControllerStyle, _ title: String?, _ message: String?, _ actions: [AnyObject], _ fields: [AnyObject]?) -> Void)?) {
alertTester = callback
}
Expand Down Expand Up @@ -249,6 +258,7 @@ public class Alert: LKAlertController {
- parameter title: Title of the button
*/
@discardableResult
public func addAction(_ title: String) -> Alert {
return addAction(title, style: .cancel, preferredAction: false, handler: nil)
}
Expand All @@ -260,6 +270,7 @@ public class Alert: LKAlertController {
- parameter style: Style of the button (.Default, .Cancel, .Destructive)
- parameter handler: Closure to call when the button is pressed
*/
@discardableResult
public override func addAction(_ title: String, style: UIAlertActionStyle, handler: actionHandler?) -> Alert {
return addAction(title, style: style, preferredAction: false, handler: handler)
}
Expand All @@ -272,6 +283,7 @@ public class Alert: LKAlertController {
- parameter handler: Closure to call when the button is pressed
- parameter preferredAction: The preferred action for the user to take from an alert.
*/
@discardableResult
public override func addAction(_ title: String, style: UIAlertActionStyle, preferredAction: Bool, handler: actionHandler?) -> Alert {
return super.addAction(title, style: style, preferredAction: preferredAction, handler: handler) as! Alert
}
Expand All @@ -281,6 +293,7 @@ public class Alert: LKAlertController {
- parameter textField: textField to add to the alert (must be a var, not let)
*/
@discardableResult
public func addTextField( _ textField: inout UITextField) -> Alert {
var field: UITextField?

Expand All @@ -305,16 +318,19 @@ public class Alert: LKAlertController {
}

///Set the view controller to present the alert in. By default this is the top controller in the window.
@discardableResult
public override func presentIn(_ source: UIViewController) -> Alert {
return super.presentIn(source) as! Alert
}

///Delay the presentation of the controller.
@discardableResult
public override func delay(_ time: TimeInterval) -> Alert {
return super.delay(time) as! Alert
}

///Set the tint color for the alert
@discardableResult
public func tint(_ color: UIColor) -> Alert {
tintColor = color
return self
Expand Down Expand Up @@ -373,6 +389,7 @@ public class ActionSheet: LKAlertController {
- parameter title: Title of the button
*/
@discardableResult
public func addAction(_ title: String) -> ActionSheet {
return addAction(title, style: .cancel, handler: nil)
}
Expand All @@ -384,21 +401,25 @@ public class ActionSheet: LKAlertController {
- parameter style: Style of the button (.Default, .Cancel, .Destructive)
- parameter handler: Closure to call when the button is pressed
*/
@discardableResult
public override func addAction(_ title: String, style: UIAlertActionStyle, handler: actionHandler?) -> ActionSheet {
return super.addAction(title, style: style, preferredAction: false, handler: handler) as! ActionSheet
}

///Set the view controller to present the alert in. By default this is the top controller in the window.
@discardableResult
public override func presentIn(_ source: UIViewController) -> ActionSheet {
return super.presentIn(source) as! ActionSheet
}

//Delay the presentation of the controller.
@discardableResult
open override func delay(_ time: TimeInterval) -> ActionSheet {
return super.delay(time) as! ActionSheet
}

///Set the tint color for the action sheet

public func tint(_ color: UIColor) -> ActionSheet {
tintColor = color
return self
Expand All @@ -410,6 +431,7 @@ public class ActionSheet: LKAlertController {
- parameter item: UIBarButtonItem that the action sheet will present from
*/
@discardableResult
public func setBarButtonItem(_ item: UIBarButtonItem) -> ActionSheet {
if let popoverController = alertController.popoverPresentationController {
popoverController.barButtonItem = item
Expand All @@ -425,6 +447,7 @@ public class ActionSheet: LKAlertController {
- parameter source: The view the action sheet will present from
*/
@discardableResult
public func setPresentingSource(_ source: UIView) -> ActionSheet {
if let popoverController = alertController.popoverPresentationController {
popoverController.sourceView = source
Expand Down

0 comments on commit 66d3e60

Please sign in to comment.