Files
Jot/Carthage/Checkouts/PromiseKit/Extensions/Social/Sources/SLComposeViewController+Promise.swift
James Griffin be7b6b5881 Add PromiseKit dependency
- Added PromiseKit dependency
2018-11-15 22:12:39 -04:00

49 lines
1.2 KiB
Swift

#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