Using the SDK

Initialize the SDK

When your app is initialized, run the following code to initialize the Stitch SDK. The application(_:didFinishLaunchWithOptions) method of your AppDelegate.swift can be an appropriate place for this initialization step. Be sure to import StitchCore.

// at the top of the file
import StitchCore
// in `application(_:didFinishLaunchWithOptions)`
do {
_ = try Stitch.initializeDefaultAppClient(
withClientAppID: "your-client-app-id"
)
} catch {
print("Failed to initialize MongoDB Stitch iOS SDK: (error)")
// note: This initialization will only fail if an incomplete configuration is
// passed to a client initialization method, or if a client for a particular
// app ID is initialized multiple times. See the documentation of the "Stitch"
// class for more details.
}

To get a client to use for logging in and communicating with Stitch, use Stitch.defaultAppClient.