StitchAppClient
public protocol StitchAppClient
The StitchAppClient has the fundamental set of methods for communicating with a MongoDB
Stitch application backend.
An implementation can be initialized or retrieved using the Stitch utility class.
This protocol provides access to the StitchAuth for login and authentication.
Using serviceClient, you can retrieve services, including the RemoteMongoClient for reading
and writing on the database. To create a RemoteMongoClient, pass remoteMongoClientFactory
into serviceClient(fromFactory:withName).
You can also use it to execute Stitch Functions.
Finally, its StitchPush object can register the current user for push notifications.
-
The
StitchAuthobject 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 a general-purpose service client for the Stitch service associated with the specified name. Use this for services which do not have a well-defined interface in the SDK.
Declaration
Swift
func serviceClient(withServiceName serviceName: String) -> StitchServiceClientParameters
withServiceNameThe name of the desired service in MongoDB Stitch.
-
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. -
Retrieves the service client for the Stitch service associated with the specified name and factory.
Declaration
Swift
func serviceClient<T>(fromFactory factory: AnyNamedThrowingServiceClientFactory<T>, withName serviceName: String) throws -> TParameters
fromFactoryAn
AnyNamedThrowingServiceClientFactoryobject which contains aNamedThrowingServiceClientFactoryclass 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.
-
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