Docs Menu

Application Services - Swift SDK

On this page

  • Overview
  • The App Client
  • Authentication & User Management
  • Calling Functions
  • Accessing MongoDB
  • Sync Data
  • Partition-Based Sync
  • Flexible Sync

Realm SDKs let you connect your client apps to the App Services backend. The SDKs provide the functionality needed to authenticate users with any of the built-in authentication providers, call backend functions, and directly access a linked MongoDB data source. You can also use an Atlas App Services App to sync data between devices.

When using the SDK to access the Atlas App Services backend, you start with a App object. This object provides all other functionality related to App Services. The App object is initialized with the Atlas App Services App ID, which you can find in the App Services UI.


To learn how to initialize the App client, see Connect to an Atlas App Services backend - Swift SDK.

One of the most challenging aspects of client development is implementing a robust and secure authentication system. With the Realm SDKs, however, you can use any of the Atlas App Services authentication providers with very minimal backend setup or client-side code required. With the authentication APIs, you can implement the following functionality:

  • Creation of new user accounts
  • User log-in and log-out
  • Multiple users logged on at the same time on the same device
  • Linking user accounts from different providers
  • Providing custom user data

To learn how to set up authentication with different providers, see Authenticate Users - Swift SDK.

To learn how to manage multiple users, see Multi-User Applications - Swift SDK.

To learn how to link user accounts, see Link User Identities - Swift SDK.

To learn how to provide custom user data, see Custom User Data - Swift SDK.

Atlas Functions enable you to define and execute server-side logic for your application. You can call these Functions from your client applications via the Realm SDKs. These server-side functions can run under the context of the authenticated user, and thus honor the rules, roles, and permissions that you have assigned to your collections.

By using Functions, you provide a secure way for a variety of client applications to share complex functionality without having to reproduce that logic client-side.


To learn how to call Functions, see Call a Function.

The Realm SDKs include APIs for accessing a MongoDB Atlas instance directly. With these APIs, you can perform all of the standard CRUD operations from your client. For security, you configure server-side data access rules to dynamically determine read & write permissions for every object that is accessed.


To learn how to use the MongoDB APIs, see Query MongoDB.

Atlas Device Sync automatically synchronizes data between client applications and an Atlas App Services backend. When a client device is online, Sync asynchronously synchronizes data in a background thread between the device and your backend Atlas App Services App.

When you use Sync in your client application, your implementation must match the Sync Mode you select in your backend App configuration. The Sync Mode options are:

  • Partition-Based Sync
  • Flexible Sync

You can only use one Sync Mode for your application. You cannot mix Partition-Based Sync and Flexible Sync within the same App.

See also:

When you select Partition-Based Sync for your backend App configuration, your client implementation must include a partition value. This is the value of the partition key field you select when you configure Partition-Based Sync.

The partition value determines which data the client application can access.

You pass in the partition value when you open a synced realm.

New in version 10.22.0.

When you select Flexible Sync for your backend App configuration, your client implementation must include subscriptions to queries on queryable fields. Flexible Sync works by synchronizing data that matches query subscriptions you maintain in the client application.

A subscription set contains a set of queries. Flexible Sync returns documents matching those queries, where the user has the appropriate permissions to read and/or read and write the documents. If documents match the query, but the client does not have the permission to read or write them, they do not sync to the client application.

You can form queries using Realm Query Language.


Flexible Sync does not support all the operators available in Realm Query Language. See Flexible Sync RQL Limitations for details.

Subscription sets are based on a specific type of realm object. You might have multiple subscriptions if you have many types of realm objects.

To use Flexible Sync in your client application, open a synced realm with a flexible sync configuration. Then, manage subscriptions to determine which documents to sync.

←  API Reference - Swift SDKConnect to an Atlas App Services backend - Swift SDK →
Give Feedback
© 2022 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.