Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu

Atlas Device SDK for Swift

Utilice el Atlas Device SDK para Swift para desarrollar aplicaciones para iOS, macOS, watchOS y tvOS en Swift y Objective-C.

Learning Paths
Ícono de funciones

Inicio rápido

Ejemplos de código con una explicación mínima sobre cómo trabajar con el SDK de Swift. Escribir en la base de datos del dispositivo y sincronizar con otros dispositivos.

Consulta Ejemplos de código

Icono de Realm Mobile

Working Example App

Aprende con el ejemplo diseccionando una aplicación cliente de SwiftUI en funcionamiento que usa el Swift SDK.

Explore an Example App

Icono de tutorial

Tutorial guiado

Sigue un tutorial guiado para aprender a adaptar la aplicación de ejemplo y así crear tu propia aplicación funcional.

Seguir el tutorial

Qué puedes hacer

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.

1

Usa Swift Package Manager, CocoaPods o Carthage para Instalar el SDK para iOS, macOS, tvOS y watchOS en tu Proyecto.

Importar RealmSwift en los archivos de su proyecto para comenzar.

2

Utiliza Swift para definir idiomáticamente un esquema de objeto.

3

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.

4

Cree, lea, actualice y elimine objetos de la base de datos del dispositivo. Filtre los datos con la sintaxis .where del SDK, que permite la seguridad de tipos, o construya un NSPredicate.

5

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.

Ilustración móvil del SDK del dispositivo Atlas
1

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.

Luego, conéctate al backend desde tu cliente.

2

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.

3

Configurar y abrir una base de datos sincronizada. Suscribirse a una consulta para determinar qué datos puede leer y escribir la base de datos sincronizada.

4

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.

Ilustración de Device Sync

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.

SwiftUI Property Wrappers Offer Realm/SwiftUI Integration
struct SearchableDogsView: View {
@ObservedResults(Dog.self) var dogs
@State 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)
}
}
}
}
}
Ilustración móvil del SDK del dispositivo Atlas

You can call serverless Functions from your client application that run in an App Services backend.

You can query data stored in MongoDB directly from your client application code.

Autentica a los usuarios con proveedores de autenticación integrados y de terceros. Usa el usuario autenticado para acceder a App Services.

App Services Illustration
Documentación esencial
Icono del reino

Swift API Reference

Explora los docs de referencia generados para las API Swift del SDK.

Swift API Reference

Icono del reino

Referencia de API de Objective-C

Explore generated reference docs for the SDK's Objective-C APIs.

Referencia de API de Objective-C

Icono de tutorial

SwiftUI Quick Start

Comience a desarrollar con SwiftUI.

Explora el Inicio rápido

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.

Ícono de sincronización asimétrica

Analytics/Telemetrics Data

Take sensor readings, push data to Atlas, and display the results in Atlas Charts or a time series collection.

Aplicación de ejemplo

Ícono de transferencia móvil en la nube

Connection State Change & Error Handling

Aprende las mejores prácticas para manejar los errores de sincronización y restablecimientos de clientes.

Aplicación de ejemplo

Icono de reino sin conexión

Offline Login and Database Access

Log in a Device Sync user and open a synced database offline.

Aplicación de ejemplo

Transaction Icon

Integrating In-App Purchases

Use StoreKit to add in-app purchases to a Device Sync-enabled recipe library app.

Aplicación de ejemplo