StitchAppClient
public protocol StitchAppClient
The fundamental set of methods for communicating with a MongoDB Stitch application.
Contains methods for executing Stitch functions and retrieving clients for Stitch services,
contains a StitchAuth object to manage the authentication state of the client, and contains a
StitchPush object to register the current user for push notifications. An implementation can be instantiated using
the Stitch utility class.
-
The StitchAuth object representing the authentication state of this client. Includes methods for logging in and logging out.
Important
Authentication state can be persisted beyond the lifetime of an application. A StitchAppClient retrieved from theStitchsingleton may or may not be authenticated when first initialized.Declaration
Swift
var auth: StitchAuth { get }
-
The push notifications component of the app. This is used for registering the currently signed in user for push notifications.
Declaration
Swift
var push: StitchPush { get }
-
Retrieves the service client for the Stitch service associated with the specified name and factory.
Declaration
Swift
func serviceClient<T>(fromFactory factory: AnyNamedServiceClientFactory<T>, withName serviceName: String) -> TParameters
fromFactoryAn
AnyNamedServiceClientFactoryobject which contains aNamedServiceClientFactoryclass which will provide the client for this service. Each available service has a static factory which can be used for this method.withNameThe name of the service as defined in the MongoDB Stitch application.
Return Value
a service client whose type is determined by the
Ttype parameter of theAnyNamedServiceClientFactorypassed in thefromFactoryparameter. -
Retrieves the service client for the Stitch service associated with the specificed factory.
Declaration
Swift
func serviceClient<T>(fromFactory factory: AnyNamedServiceClientFactory<T>) -> TParameters
fromFactoryAn
AnyNamedServiceClientFactoryobject which contains aNamedServiceClientFactoryclass which will provide the client for this service. Each available service has a static factory which can be used for this method.Return Value
a service client whose type is determined by the
Ttype parameter of theAnyNamedServiceClientFactorypassed in thefromFactoryparameter. -
Retrieves the service client for the Stitch service associated with the service type with the specified factory.
Declaration
Swift
func serviceClient<T>(fromFactory factory: AnyThrowingServiceClientFactory<T>) throws -> TParameters
fromFactoryAn
AnyThrowingServiceClientFactoryobject which contains aThrowingServiceClientFactoryclass which will provide the client for this service. Each available service has a static factory which can be used for this method.Return Value
a service client whose type is determined by the
Ttype parameter of theAnyThrowingServiceClientFactorypassed in thefromFactoryparameter.
-
Calls the MongoDB Stitch function with the provided name and arguments, and decodes the result of the function into a
Decodabletype as specified by theTtype parameter.Declaration
Swift
func callFunction<T: Decodable>(withName name: String, withArgs args: [BsonValue], _ completionHandler: @escaping (StitchResult<T>) -> Void)Parameters
withNameThe name of the Stitch function to be called.
withArgsThe
BSONArrayof arguments to be provided to the function.completionHandlerThe completion handler to call when the function call is complete. This handler is executed on a non-main global
DispatchQueue. If the operation is successful, the result will contain aTrepresenting the decoded result of the function call. -
Calls the MongoDB Stitch function with the provided name and arguments, ignoring the result of the function.
Declaration
Swift
func callFunction(withName name: String, withArgs args: [BsonValue], _ completionHandler: @escaping (StitchResult<Void>) -> Void)Parameters
withNameThe name of the Stitch function to be called.
withArgsThe
BSONArrayof arguments to be provided to the function.completionHandlerThe completion handler to call when the function call is complete. This handler is executed on a non-main global
DispatchQueue. -
Calls the MongoDB Stitch function with the provided name and arguments, and decodes the result of the function into a
Decodabletype as specified by theTtype parameter. Also accepts a timeout. Use this for functions that may run longer than the client-wide default timeout (15 seconds by default).Declaration
Swift
func callFunction<T: Decodable>(withName name: String, withArgs args: [BsonValue], withRequestTimeout requestTimeout: TimeInterval, _ completionHandler: @escaping (StitchResult<T>) -> Void)Parameters
withNameThe name of the Stitch function to be called.
withArgsThe
BSONArrayof arguments to be provided to the function.withRequestTimeoutThe number of seconds the client should wait for a response from the server before failing with an error.
completionHandlerThe completion handler to call when the function call is complete. This handler is executed on a non-main global
DispatchQueue. If the operation is successful, the result will contain aTrepresenting the decoded result of the function call. -
Calls the MongoDB Stitch function with the provided name and arguments, ignoring the result of the function. Also accepts a timeout. Use this for functions that may run longer than the client-wide default timeout (15 seconds by default).
Declaration
Swift
func callFunction(withName name: String, withArgs args: [BsonValue], withRequestTimeout requestTimeout: TimeInterval, _ completionHandler: @escaping (StitchResult<Void>) -> Void)Parameters
withNameThe name of the Stitch function to be called.
withArgsThe
BSONArrayof arguments to be provided to the function.withRequestTimeoutThe number of seconds the client should wait for a response from the server before failing with an error.
completionHandlerThe completion handler to call when the function call is complete. This handler is executed on a non-main global
DispatchQueue.
StitchAppClient Protocol Reference