Skip to content

Commit

Permalink
Added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Sargent committed Jul 14, 2015
1 parent 87d0084 commit 4c52be4
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions Pod/Classes/LKAlertController.swift
Expand Up @@ -10,8 +10,10 @@ import UIKit


public class LKAlertController {
/** Internal alert controller to present to the user */
internal var alertController: UIAlertController

/** Title of the alert controller */
internal var title: String? {
get {
return alertController.title
Expand All @@ -21,6 +23,7 @@ public class LKAlertController {
}
}

/** Message of the alert controller */
internal var message: String? {
get {
return alertController.title
Expand All @@ -30,10 +33,22 @@ public class LKAlertController {
}
}

/**
Initialize a new LKAlertController
:params: style .ActionSheet or .Alert
*/
public init(style: UIAlertControllerStyle) {
alertController = UIAlertController(title: nil, message: nil, preferredStyle: style)
}

/**
Add a new button to the controller.
:params: title Title of the button
:params: style Style of the button (.Default, .Cancel, .Destructive)
:params: handler Closure to call when the button is pressed
*/
public func addAction(title: String, style: UIAlertActionStyle, handler: ((UIAlertAction!) -> Void)? = nil) -> LKAlertController {
var action = UIAlertAction(title: title, style: style, handler: { _ in })
if let handler = handler {
Expand All @@ -45,14 +60,28 @@ public class LKAlertController {
return self
}

/**
Present in the view
*/
public func show() {
show(animated: true, completion: nil)
}

/**
Present in the view
:params: animated Whether to animate into the view or not
*/
public func show(#animated: Bool) {
show(animated: animated, completion: nil)
}

/**
Present in the view
:params: animated Whether to animate into the view or not
:params: completion Closure to call when the button is pressed
*/
public func show(#animated: Bool, completion: (() -> Void)?) {
if let viewController = UIApplication.sharedApplication().keyWindow?.rootViewController {
//Find the presented view controller
Expand All @@ -65,68 +94,133 @@ public class LKAlertController {
}
}

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


public class Alert: LKAlertController {
/**
Create a new alert without a title or message
*/
public init() {
super.init(style: .Alert)
}

/**
Create a new alert with a title
:params: title Title of the alert
*/
public init(title: String?) {
super.init(style: .Alert)
self.title = title
}

/**
Create a new alert with a message
:params: message Body of the alert
*/
public init(message: String?) {
super.init(style: .Alert)
self.message = message
}

/**
Create a new alert with a title and message
:params: title Title of the alert
:params: message Body of the alert
*/
public init(title: String?, message: String?) {
super.init(style: .Alert)
self.title = title
self.message = message
}

/**
Add a new button to the alert. It will not have an action and will have the Cancel style
:params: title Title of the button
*/
public func addAction(title: String) -> Alert {
return addAction(title, style: .Cancel, handler: nil)
}

/**
Add a new button to the alert.
:params: title Title of the button
:params: style Style of the button (.Default, .Cancel, .Destructive)
:params: handler Closure to call when the button is pressed
*/
public override func addAction(title: String, style: UIAlertActionStyle, handler: ((UIAlertAction!) -> Void)?) -> Alert {
return super.addAction(title, style: style, handler: handler) as! Alert
}
}


public class ActionSheet: LKAlertController {
/**
Create a new action sheet without a title or message
*/
public init() {
super.init(style: .ActionSheet)
}

/**
Create a new action sheet with a title
:params: title Title of the action sheet
*/
public init(title: String?) {
super.init(style: .ActionSheet)
self.title = title
}

/**
Create a new action sheet with a message
:params: message Body of the action sheet
*/
public init(message: String?) {
super.init(style: .ActionSheet)
self.message = message
}

/**
Create a new action sheet with a title and message
:params: title Title of the action sheet
:params: message Body of the action sheet
*/
public init(title: String?, message: String?) {
super.init(style: .ActionSheet)
self.title = title
self.message = message
}

/**
Add a new button to the action sheet. It will not have an action and will have the Cancel style
:params: title Title of the button
*/
public func addAction(title: String) -> ActionSheet {
return addAction(title, style: .Cancel, handler: nil)
}

/**
Add a new button to the action sheet.
:params: title Title of the button
:params: style Style of the button (.Default, .Cancel, .Destructive)
:params: handler Closure to call when the button is pressed
*/
public override func addAction(title: String, style: UIAlertActionStyle, handler: ((UIAlertAction!) -> Void)?) -> ActionSheet {
return super.addAction(title, style: style, handler: handler) as! ActionSheet
}
Expand Down

0 comments on commit 4c52be4

Please sign in to comment.