Add PromiseKit dependency

- Added PromiseKit dependency
This commit is contained in:
2018-11-15 22:08:00 -04:00
parent 2689d86c18
commit be7b6b5881
541 changed files with 46282 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
#if !os(OSX)
import Social.SLComposeViewController
import UIKit.UIViewController
#if !PMKCocoaPods
import PromiseKit
#endif
/**
To import this `UIViewController` category:
use_frameworks!
pod "PromiseKit/Social"
And then in your sources:
import PromiseKit
*/
extension UIViewController {
/// Presents the message view controller and resolves with the user action.
public func promise(_ vc: SLComposeViewController, animated: Bool = true, completion: (() -> Void)? = nil) -> Promise<Void> {
present(vc, animated: animated, completion: completion)
return Promise { seal in
vc.completionHandler = { result in
if result == .cancelled {
seal.reject(SLComposeViewController.PMKError.cancelled)
} else {
seal.fulfill(())
}
}
}
}
}
extension SLComposeViewController {
/// Errors representing PromiseKit SLComposeViewController failures
public enum PMKError: CancellableError {
/// The user cancelled the view controller.
case cancelled
/// - Returns: true
public var isCancelled: Bool {
switch self { case .cancelled: return true }
}
}
}
#endif