Protocols
The following protocols are available globally.
-
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<T>
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,futures
, and one static property also namedfutures
. These properties both return aFutureProvider<Source>
which you can extend to provide support for futures to any type. The returnedFutureProvider<Source>
provides the propertysource
for access to the instance it should be acting on.As an example, here’s how we implement support for presenting view controllers:
extension UIViewController: FutureSupport {} extension FutureProvider 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.futures.present( otherViewController, animated: true ).then { someOtherFutureReturningMethod() }
Declaration
Swift
public protocol FutureSupport