Skip to content

Commit

Permalink
merge v 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mshrwtnb committed Oct 1, 2017
2 parents ff19b61 + 6f59b02 commit 5450b5a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ALRT.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ALRT"
s.version = "1.0"
s.version = "1.1"
s.summary = "ALRT is an easy-to-create UIAlertController framework."
s.description = <<-DESC
* Easy-to-Create. As easy as 'ALRT.create(.alert).addOK().show()''
Expand Down
21 changes: 13 additions & 8 deletions ALRT/ALRT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ open class ALRT {
case sourceViewControllerNil
}

fileprivate var alert: UIAlertController?
var alert: UIAlertController?

fileprivate init(){}

fileprivate init(title: String?, message: String?, preferredStyle: UIAlertControllerStyle){
fileprivate init(title: String?, message: String?, preferredStyle: UIAlertControllerStyle) {
self.alert = UIAlertController(title: title,
message: message,
preferredStyle: preferredStyle)
Expand Down Expand Up @@ -68,6 +68,7 @@ open class ALRT {
- returns: Self
*/

@discardableResult
open func fetch(_ handler: ((_ alertController: UIAlertController?) -> Void)) -> Self {
handler(self.alert)
return self
Expand All @@ -83,6 +84,7 @@ open class ALRT {
- returns: Self
*/

@discardableResult
open func addTextField(_ configurationHandler: ((_ textField: UITextField) -> Void)?) -> Self{
guard alert?.preferredStyle == .alert else {
return self
Expand Down Expand Up @@ -111,22 +113,21 @@ open class ALRT {
- returns: Self
*/

@discardableResult
open func addAction(_ title: String?,
style: UIAlertActionStyle = .default,
preferred: Bool = false,
handler: ((_ action: UIAlertAction, _ textFields: [UITextField]?) -> Void)? = nil) -> Self {

let action = UIAlertAction(title: title, style: style){ action in
let action = UIAlertAction(title: title, style: style) { action in
handler?(action, self.alert?.preferredStyle == .alert ? self.alert?.textFields : nil)
self.alert = nil
}

alert?.addAction(action)

if #available(iOS 9.0, *) {
if preferred {
alert?.preferredAction = action
}
if preferred {
alert?.preferredAction = action
}

return self
Expand All @@ -145,6 +146,7 @@ open class ALRT {
- returns: Self
*/

@discardableResult
open func addOK(_ title: String = "OK",
style: UIAlertActionStyle = .default,
preferred: Bool = false,
Expand All @@ -164,6 +166,7 @@ open class ALRT {
- returns: Self
*/

@discardableResult
open func addCancel(_ title: String = "Cancel",
style: UIAlertActionStyle = .cancel,
preferred: Bool = false,
Expand All @@ -183,6 +186,7 @@ open class ALRT {
- returns: Self
*/

@discardableResult
open func addDestructive(_ title: String?,
style: UIAlertActionStyle = .destructive,
preferred: Bool = false,
Expand All @@ -201,6 +205,7 @@ open class ALRT {
- returns: Self
*/

@discardableResult
open func configurePopoverPresentation(_ configurationHandler:((_ popover: UIPopoverPresentationController?) -> Void)? = nil) -> Self {

configurationHandler?(alert?.popoverPresentationController)
Expand All @@ -220,7 +225,7 @@ open class ALRT {

open func show(_ viewControllerToPresent: UIViewController? = nil,
animated: Bool = true,
completion: @escaping ((ALRT.Result) -> Void) = {_ in } ) {
completion: @escaping ((ALRT.Result) -> Void) = { _ in } ) {

guard let alert = self.alert else {
completion(.failure(.alertControllerNil))
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down

0 comments on commit 5450b5a

Please sign in to comment.