Protocols
The following protocols are available globally.
-
Type-erasure for
See moreFuture<Value>Declaration
Swift
public protocol AnyFuture : AnyObject -
Undocumented
See moreDeclaration
Swift
public protocol AnyFutureObserver : AnyObject -
A protocol that can be used to add support for futures to a type of your choice.
When you want an API that supports futures, i types that already have methods with callbacks, the signatures of the method providing the
Future<Value>and the original function can conflict, especially when working with methods where a completion callback is optional. To get around this, when this protocol is conformed to by a type, it will expose one instance property,promise, and one static property also namedpromise. These properties both return aPromises<Source>which you can extend to provide support for futures to any type. The returnedPromises<Source>provides the propertysourcefor access to the instance it should be acting on.As an example, here’s how we implement support for presenting view controllers:
extension UIViewController: PromisesExtended {} extension Promises where Source: UIViewController { func present(_ viewControllerToPresent: UIViewController, animated: Bool) -> Future<Void> { let promise = Promise<Void>() DispatchQueue.main.async { self.source.present(viewControllerToPresent, animated: animated) { promise.fulfill() } } return promise.future } }Using this implementation is now possible.
See moreviewController.promise.present( otherViewController, animated: true ).flatMap { someOtherFutureReturningMethod() }Declaration
Swift
public protocol PromisesExtended
View on GitHub
Protocols Reference