React Native executes JavaScript in a dedicated worker thread so common concurrency primitives are unavailable.

// Query and update the result in another thread
dispatch_async(dispatch_queue_create("background",0),^{Dog*theDog=[[DogobjectsWhere:@"age == 1"]firstObject];RLMRealm*realm=[RLMRealmdefaultRealm];[realmbeginWriteTransaction];theDog.age=3;[realmcommitWriteTransaction];});

// Query and update from any threadDispatchQueue(label:"background").async{letrealm=try!Realm()lettheDog=realm.objects(Dog.self).filter("age == 1").firsttry!realm.write{theDog!.age=3}}

// Generate a random encryption keyvarkey=Data(count:64)_=key.withUnsafeMutableBytes{bytesinSecRandomCopyBytes(kSecRandomDefault,64,bytes)}// Open the encrypted Realm fileletrealm=try!Realm(configuration:Realm.Configuration(encryptionKey:key))// Use the Realm as normalletdogs=realm.objects(Dog.self).filter("name contains 'Fido'")

// Generate a random encryption keybyte[]key=newbyte[64];newSecureRandom().nextBytes(key);// Open the encrypted Realm fileRealmConfigurationrealmConfiguration=newRealmConfiguration.Builder().encryptionKey(key).build();// Use the Realm as normalRealmrealm=Realm.getInstance(config);RealmResults<Dog>results=realm.where(Dog.class).contains("name","Fido").findAll();

// Generate a random encryption key
varrandom=newRandom();varkey=newByte[64];rnd.NextBytes(key);varconfig=newRealmConfiguration("Mine.realm");config.EncryptionKey=key;// Open the encrypted Realm file
varrealm=Realm.GetInstance(config);// Use the Realm as normal
vardogs=realm.All<Dog>().Where(d=>d.Name.Contains("Fido"));

// Generate a random encryption keyvarkey=Data(count:64)_=key.withUnsafeMutableBytes{bytesinSecRandomCopyBytes(kSecRandomDefault,64,bytes)}// Open the encrypted Realm fileletrealm=try!Realm(configuration:Realm.Configuration(encryptionKey:key))// Use the Realm as normalletdogs=realm.objects(Dog.self).filter("name contains 'Fido'")

// Generate a random encryption keybyte[]key=newbyte[64];newSecureRandom().nextBytes(key);// Open the encrypted Realm fileRealmConfigurationrealmConfiguration=newRealmConfiguration.Builder().encryptionKey(key).build();// Use the Realm as normalRealmrealm=Realm.getInstance(config);RealmResults<Dog>results=realm.where(Dog.class).contains("name","Fido").findAll();

// Generate a random encryption key
varrandom=newRandom();varkey=newByte[64];rnd.NextBytes(key);varconfig=newRealmConfiguration("Mine.realm");config.EncryptionKey=key;// Open the encrypted Realm file
varrealm=Realm.GetInstance(config);// Use the Realm as normal
vardogs=realm.All<Dog>().Where(d=>d.Name.Contains("Fido"));

Realmrealm=Realm.getDefaultInstance();// Query in the backgroundRealmResults<Dog>results=realm.where(Dog.class).greaterThan("age",5).findAllAsync();// Use ChangeListeners to be notified about updatesresults.addChangeListener(newRealmChangeListener<RealmResults<Dog>(){@OverridepublicvoidonChange(RealmResults<Dog>results){// Update UI}});// Or RxJavaObservable<RealmResults<Dog>>obs=results.asObservable();

// To bind a ListView to results of a query
publicpartialclassDogsPage:ContentPage{internalRealmrealm;internalIEnumerable<Dog>Entries{get;}publicDogsPage(){InitializeComponent();realm=Realm.GetInstance();// Results from queries will automatically notify the Binding
// and update the ListView accordingly
Entries=realm.All<Dog>().Where(d=>d.Age>5)DogsList.ItemsSource=Entries;}<ListViewx:Name="DogsList"><ListView.ItemTemplate><DataTemplate><TextCellText="{Binding Name}"Detail="{Binding Age, StringFormat='is {0:#}'}"/></DataTemplate></ListView.ItemTemplate></ListView>

Build reactive apps with live objects

Realm objects are always live, which means that they always have the latest data. Subscribe to notifications to get updates when data changes, then update your UI. Your app will never be out of date again.

// Authenticating the UserRealm.Sync.User.registerWithProvider('http://realm.example.co:9080','google',googleAccessToken,(error,user)=>{if(!error){// Opening a remote Realmvarrealm=newRealm({sync:{user:user,url:'realm://realm.example.co:9080/~/userRealm',}});// Any changes made to this Realm will be synced across all devices!}})

// Authenticating the User
[RLMSyncUserlogInWithCredentials:[RLMSyncCredentialscredentialsWithGoogleToken:@"google token"]authServerURL:[NSURLURLWithString:@"http://realm.example.com:9080"]onCompletion:^(RLMSyncUser*user,NSError*error){if(user){// Opening a remote Realm
NSURL*realmURL=[NSURLURLWithString:@"realm://realm.example.com:9080/~/userRealm"];RLMRealmConfiguration*config=[[RLMRealmConfigurationalloc]init];config.syncConfiguration=[[RLMSyncConfigurationalloc]initWithUser:userrealmURL:realmURL];RLMRealm*realm=[RLMRealmrealmWithConfiguration:configerror:nil];// Any changes made to this Realm will be synced across all devices!
}elseif(error){// handle error
}}];

// Authenticating the UserSyncUser.logIn(with:.google(token:"google token"),server:URL(string:"http://realm.example.com:9080")!){user,errorinifletuser=user{// Opening a remote RealmletrealmURL=URL(string:"realm://realm.example.com:9080/~/userRealm")!letconfig=Realm.Configuration(syncConfiguration:SyncConfiguration(user:user,realmURL:realmURL))letrealm=try!Realm(configuration:config)// Any changes made to this Realm will be synced across all devices!}elseifleterror=error{// handle error}}

// Authenticating the UserUseruser=User.login(Credentials.google("google token"),"http://realm.example.com:9080/auth");// Opening a remote RealmStringrealmURL="realm://realm.example.com:9080/~/userRealm";SyncConfigurationconfig=newSyncConfiguration.Builder(user,realmURL).build();Realmrealm=Realm.getInstance(config);// Any changes made to this Realm will be synced across all devices!

Sync data seamlessly

With the Realm Platform extensions, the Realm Database works perfectly with the Platform. All you need to do is set your Realm Platform Instance URL; everything else stays exactly the same. Data sync will automatically happen whenever you save, with no work from you.

// Authenticating the UserRealm.Sync.User.registerWithProvider('http://realm.example.co:9080','google',googleAccessToken,(error,user)=>{if(!error){// Opening a remote Realmvarrealm=newRealm({sync:{user:user,url:'realm://realm.example.co:9080/~/userRealm',}});// Any changes made to this Realm will be synced across all devices!}})

// Authenticating the User
[RLMSyncUserlogInWithCredentials:[RLMSyncCredentialscredentialsWithGoogleToken:@"google token"]authServerURL:[NSURLURLWithString:@"http://realm.example.com:9080"]onCompletion:^(RLMSyncUser*user,NSError*error){if(user){// Opening a remote Realm
NSURL*realmURL=[NSURLURLWithString:@"realm://realm.example.com:9080/~/userRealm"];RLMRealmConfiguration*config=[[RLMRealmConfigurationalloc]init];config.syncConfiguration=[[RLMSyncConfigurationalloc]initWithUser:userrealmURL:realmURL];RLMRealm*realm=[RLMRealmrealmWithConfiguration:configerror:nil];// Any changes made to this Realm will be synced across all devices!
}elseif(error){// handle error
}}];

// Authenticating the UserSyncUser.logIn(with:.google(token:"google token"),server:URL(string:"http://realm.example.com:9080")!){user,errorinifletuser=user{// Opening a remote RealmletrealmURL=URL(string:"realm://realm.example.com:9080/~/userRealm")!letconfig=Realm.Configuration(syncConfiguration:SyncConfiguration(user:user,realmURL:realmURL))letrealm=try!Realm(configuration:config)// Any changes made to this Realm will be synced across all devices!}elseifleterror=error{// handle error}}

// Authenticating the UserUseruser=User.login(Credentials.google("google token"),"http://realm.example.com:9080/auth");// Opening a remote RealmStringrealmURL="realm://realm.example.com:9080/~/userRealm";SyncConfigurationconfig=newSyncConfiguration.Builder(user,realmURL).build();Realmrealm=Realm.getInstance(config);// Any changes made to this Realm will be synced across all devices!

The Realm Database is developed in the open. Thousands of developers work with us on GitHub, plus hundreds more write add-ons that work with the Realm Database. The 25,000 stars on our repos speak for themselves.

Realm Studio

Realm Studio is our premiere developer tool, built so you can easily manage the Realm Database and Realm Platform. With Realm Studio, you can open and edit local and synced Realms, and administer any Realm Object Server instance. Download it now on macOS, Windows, or Linux.