Atlas Device SDK for Swift
Use the Atlas Device SDK for Swift to develop iOS, macOS, watchOS and tvOS apps in Swift and Objective-C.
Get Started with the Swift SDK
![Functions Icon](/realm/docsworker-xlarge/snyk-upgrade-11dbd93083b763076e0095446625be50/images/icons/branding_2022/Technical_ATLAS_Functions3x.png)
Quick Start
Minimal-explanation code examples of how to work with the Swift SDK. Write to the device database, and sync with other devices.
![Realm Mobile Icon](/realm/docsworker-xlarge/snyk-upgrade-11dbd93083b763076e0095446625be50/images/icons/branding_2022/Technical_REALM_Mobile3x.png)
Working Example App
Learn from example by dissecting a working SwiftUI client app that uses the Swift SDK.
![Tutorial Icon](/realm/docsworker-xlarge/snyk-upgrade-11dbd93083b763076e0095446625be50/images/icons/branding_2022/General_CONTENT_Tutorial3x.png)
Guided Tutorial
Follow a guided tutorial to learn how to adapt the example app to create your own working app.
Develop Apps with the SDK
Use the SDK's open-source database - Realm - as an object store on the device. Use Device Sync to keep data in sync with your MongoDB Atlas cluster and other clients.
Install the Swift SDK
Use Swift Package Manager, CocoaPods, or Carthage to Install the SDK for iOS, macOS, tvOS, and watchOS in your project.
Import RealmSwift
in your project files to get started.
Define an Object Schema
Use Swift to idiomatically define an object schema.
Open a Database
The SDK's database - Realm - stores objects in files on your device. Or you can open an in-memory database which does not create a file. Configure and open a database to specify the options for your database file.
Read and Write Data
Create, read, update, and delete objects from the device database. Filter data using the SDK's type-safe .where syntax, or construct an NSPredicate.
React to Changes
Live objects mean that your data is always up-to-date. You can register a notification handler to watch for changes and perform some logic, such as updating your UI. Or in SwiftUI, use the Swift property wrappers to update Views when data changes.
![Atlas Device SDK Mobile Illustration](/realm/docsworker-xlarge/snyk-upgrade-11dbd93083b763076e0095446625be50/static/a142cbd5221d3bf0be5b10b3a88b17cb/241a1/Technical_SOFTWARE_Connect(2)_Spot.webp)
Connect to an Atlas App Services App
Configure Device Sync in an App Services App. Define data access rules. Use Development Mode to infer your schema from your Swift or Objective-C data model.
Then, connect to the backend from your client.
Authenticate a User
Use one of our authentication providers to authenticate a user. App Services provides access to popular authentication providers, such as Apple, Google, or Facebook. Use our built-in email/password provider to manage users without a third-party, or use custom JWT authentication to integrate with other authentication providers. Anonymous authentication provides access without requiring a login or persisting user data.
Open a Synced Database
Configure and open a synced database. Subscribe to a query to determine what data the synced database can read and write.
Read and Write Synced Data
The APIs to read and write data are the same whether you're using a synced or non-synced database. Data that you read and write to the device is automatically kept in sync with your Atlas cluster and other clients. Apps keep working offline and deterministically sync changes whenever a network connection is available.
![Device Sync Illustration](/realm/docsworker-xlarge/snyk-upgrade-11dbd93083b763076e0095446625be50/static/3663e76ec7a23581c327070edf06db05/dab22/Technical_SOFTWARE_Sync(2)_Spot.webp)
The Swift SDK offers property wrappers and convenience features designed to make it easier to work with SwiftUI. For example View code that demonstrates common SwiftUI patterns, check out the SwiftUI documentation.
struct SearchableDogsView: View { Dog.self) var dogs ( private var searchFilter = "" var body: some View { NavigationView { // The list shows the dogs in the realm. List { ForEach(dogs) { dog in DogRow(dog: dog) } } .searchable(text: $searchFilter, collection: $dogs, keyPath: \.name) { ForEach(dogs) { dogsFiltered in Text(dogsFiltered.name).searchCompletion(dogsFiltered.name) } } } } }
![Atlas Device SDK Mobile Illustration](/realm/docsworker-xlarge/snyk-upgrade-11dbd93083b763076e0095446625be50/static/3f7aca6cc507abe957c292353f80621a/dab22/Technical_SOFTWARE_GearSettings_Spot.webp)
Call Serverless Functions
You can call serverless Functions from your client application that run in an App Services backend.
Query MongoDB Atlas
You can query data stored in MongoDB directly from your client application code.
Authenticate Users
Authenticate users with built-in and third-party authentication providers. Use the authenticated user to access App Services.
![App Services Illustration](/realm/docsworker-xlarge/snyk-upgrade-11dbd93083b763076e0095446625be50/static/292f9c683e68aeabfeae94ade95b9dba/241a1/Technical_ACTION_WrenchSettings_Spot.webp)
Recommended Reading
![Realm Icon](/realm/docsworker-xlarge/snyk-upgrade-11dbd93083b763076e0095446625be50/images/icons/branding_2022/Technical_REALM_SDK3x.png)
![Realm Icon](/realm/docsworker-xlarge/snyk-upgrade-11dbd93083b763076e0095446625be50/images/icons/branding_2022/Technical_REALM_SDK3x.png)
Objective-C API Reference
Explore generated reference docs for the SDK's Objective-C APIs.
![Tutorial Icon](/realm/docsworker-xlarge/snyk-upgrade-11dbd93083b763076e0095446625be50/images/icons/branding_2022/General_CONTENT_Tutorial3x.png)
Example Projects
Explore engineering and expert-provided example projects to learn best practices and common development patterns using the Swift SDK. Check out the Example Projects page for more sample apps.
![Asymmetric Sync icon](/realm/docsworker-xlarge/snyk-upgrade-11dbd93083b763076e0095446625be50/images/icons/branding_2023/Technical_ATLAS_AsymmetricSync10x.png)
Analytics/Telemetrics Data
Take sensor readings, push data to Atlas, and display the results in Atlas Charts or a time series collection.
![Cloud Mobile Transfer Icon](/realm/docsworker-xlarge/snyk-upgrade-11dbd93083b763076e0095446625be50/images/icons/branding_2023/General_CLOUD_Mobility10x.png)
Connection State Change & Error Handling
Learn best practices around handling Sync errors and client resets.
![Realm Offline Icon](/realm/docsworker-xlarge/snyk-upgrade-11dbd93083b763076e0095446625be50/images/icons/branding_2023/Technical_REALM_Offline10x.png)
Offline Login and Database Access
Log in a Device Sync user and open a synced database offline.
![Transaction Icon](/realm/docsworker-xlarge/snyk-upgrade-11dbd93083b763076e0095446625be50/images/icons/branding_2023/General_FEATURES_Transactions10x.png)
Integrating In-App Purchases
Use StoreKit to add in-app purchases to a Device Sync-enabled recipe library app.