Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Masahiro Watanabe committed Dec 12, 2016
2 parents b792b92 + 28f3541 commit a1edd6b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
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 = "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.
Expand Down
60 changes: 28 additions & 32 deletions ALRT/ALRT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -231,7 +231,32 @@ open class ALRT {
completion: ((_ result: Result<ALRTError>) -> 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))
Expand All @@ -243,33 +268,4 @@ open class ALRT {
completion?(.failure(Error: ALRTError.unknown))
}
}

fileprivate func privateShow(_ viewControllerToPresent: UIViewController? = nil,
animated: Bool = true,
completion: ((_ result: Result<ALRTError>) -> 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)
})

}
}
6 changes: 5 additions & 1 deletion Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0810;
ORGANIZATIONNAME = "Masahiro Watanabe";
TargetAttributes = {
DF17F7DB1D4C18DE001DF68B = {
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -244,8 +246,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";
Expand Down
2 changes: 1 addition & 1 deletion Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions Demo/Demo/DemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ 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.")

case .failure(let error):
print("The alert is not displayed. Error => \(error)")
}
})
}
}
}

Expand Down

0 comments on commit a1edd6b

Please sign in to comment.