From 21bcdb530df425deb14201d72709cf473248177b Mon Sep 17 00:00:00 2001 From: Masahiro Watanabe Date: Mon, 12 Dec 2016 21:48:33 +0900 Subject: [PATCH 1/3] Fixed to return success result --- ALRT/ALRT.swift | 31 +++++++++++++++++++++++++++--- Demo/Demo/DemoViewController.swift | 4 ++-- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/ALRT/ALRT.swift b/ALRT/ALRT.swift index 5857875..46de65b 100644 --- a/ALRT/ALRT.swift +++ b/ALRT/ALRT.swift @@ -60,8 +60,8 @@ open class ALRT { */ open class func create(_ style: UIAlertControllerStyle, - title: String?, - message: String?) -> ALRT { + title: String? = nil, + message: String? = nil) -> ALRT { return ALRT(title: title, message: message, preferredStyle: style) } @@ -231,7 +231,32 @@ open class ALRT { completion: ((_ result: Result) -> Void)? = nil) { do { - try privateShow() + + guard + let alert = self.alert + else { + throw ALRTError.alertControllerNil + } + + if UIDevice.current.userInterfaceIdiom == .pad && + alert.preferredStyle == .actionSheet && + alert.popoverPresentationController?.sourceView == nil && + alert.popoverPresentationController?.barButtonItem == nil { + throw ALRTError.popoverNotSet + } + + let sourceViewController: UIViewController? = { + let viewController = viewControllerToPresent ?? UIApplication.shared.keyWindow?.rootViewController + if let navigationController = viewController as? UINavigationController { + return navigationController.visibleViewController + } + return viewController + }() + + sourceViewController?.present(alert, animated: animated) { _ in + completion?(.success) + } + } catch ALRTError.alertControllerNil { completion?(.failure(Error: ALRTError.alertControllerNil)) diff --git a/Demo/Demo/DemoViewController.swift b/Demo/Demo/DemoViewController.swift index 9791b9a..d1b114c 100644 --- a/Demo/Demo/DemoViewController.swift +++ b/Demo/Demo/DemoViewController.swift @@ -75,7 +75,7 @@ class DemoViewController: UIViewController { .flatMap { (placeholder: $0.placeholder ?? "No Placeholder", text: $0.text ?? "No Text") } .forEach { print("\($0.placeholder) => \($0.text)") } } - .show(completion: { result in + .show { result in switch result { case .success: print("The alert is displayed.") @@ -83,7 +83,7 @@ class DemoViewController: UIViewController { case .failure(let error): print("The alert is not displayed. Error => \(error)") } - }) + } } } From 61aebeedc68158124b223329a19c31744fa290ce Mon Sep 17 00:00:00 2001 From: Masahiro Watanabe Date: Mon, 12 Dec 2016 21:49:47 +0900 Subject: [PATCH 2/3] Removed privateShow method --- ALRT/ALRT.swift | 29 ------------------- Demo/Demo.xcodeproj/project.pbxproj | 6 +++- .../xcshareddata/xcschemes/Demo.xcscheme | 2 +- 3 files changed, 6 insertions(+), 31 deletions(-) diff --git a/ALRT/ALRT.swift b/ALRT/ALRT.swift index 46de65b..8a7e82f 100644 --- a/ALRT/ALRT.swift +++ b/ALRT/ALRT.swift @@ -268,33 +268,4 @@ open class ALRT { completion?(.failure(Error: ALRTError.unknown)) } } - - fileprivate func privateShow(_ viewControllerToPresent: UIViewController? = nil, - animated: Bool = true, - completion: ((_ result: Result) -> Void)? = nil) throws { - - guard let alert = self.alert else { - throw ALRTError.alertControllerNil - } - - if UIDevice.current.userInterfaceIdiom == .pad && - alert.preferredStyle == .actionSheet && - alert.popoverPresentationController?.sourceView == nil && - alert.popoverPresentationController?.barButtonItem == nil { - throw ALRTError.popoverNotSet - } - - let sourceViewController: UIViewController? = { - let viewController = viewControllerToPresent ?? UIApplication.shared.keyWindow?.rootViewController - if let navigationController = viewController as? UINavigationController { - return navigationController.visibleViewController - } - return viewController - }() - - sourceViewController?.present(alert, animated: animated, completion: { _ in - completion?(Result.success) - }) - - } } diff --git a/Demo/Demo.xcodeproj/project.pbxproj b/Demo/Demo.xcodeproj/project.pbxproj index d30773a..98b78d6 100644 --- a/Demo/Demo.xcodeproj/project.pbxproj +++ b/Demo/Demo.xcodeproj/project.pbxproj @@ -108,7 +108,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0810; ORGANIZATIONNAME = "Masahiro Watanabe"; TargetAttributes = { DF17F7DB1D4C18DE001DF68B = { @@ -197,8 +197,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -243,8 +245,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; diff --git a/Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme b/Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme index 49b0ff9..b26b380 100644 --- a/Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme +++ b/Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme @@ -1,6 +1,6 @@ Date: Mon, 12 Dec 2016 22:19:11 +0900 Subject: [PATCH 3/3] Updated Podspec --- .travis.yml | 5 +++++ ALRT.podspec | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8a65090 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: objective-c +os: osx +osx_image: xcode8.1 +xcode_project: MyNewProject.xcodeproj # path to your xcodeproj folder +xcode_scheme: MyNewProjectTests diff --git a/ALRT.podspec b/ALRT.podspec index cef08a3..75b0430 100644 --- a/ALRT.podspec +++ b/ALRT.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "ALRT" - s.version = "0.4" + s.version = "0.5" s.summary = "ALRT is a call-site-friendly UIAlertController framework." s.description = <<-DESC ALRT aims to be an AL(R)Ternative to tedious UIAlertController implementation process.