=> 0 realm.beginTransaction(); Dog dog = realm.createObject(Dog.class); dog.setAge(1); realm.commitTransaction(); puppies.size(); // => 1 // Change the dog from another query realm.beginTransaction(); Dog theDog = realm.where(Dog.class).equals("age", 1).findFirst(); theDog.setAge(3); realm.commitTransaction(); // Original dog is auto-updated dog.getAge(); // => 3 puppies.size(); // => 0
// => 0 because no dogs have been added to the Realm yet let myDog = Dog() myDog.name = “Rex” myDog.age = 1 try! realm.write { realm.add(myDog) } puppies.count // => 1 updated in real-time // Access the Dog in a separate query let puppy = realm.objects(Dog).filter("age == 1").first try! realm.write { puppy.age = 3 } // Original Dog object is auto-updated myDog.age // => 3 puppies.count // => 0
Java POJO User proxyUser = realm.copyToRealm(jUser); // Convert POJO to Proxy User proxyUser = realm.createObject(User.class); // Proxy // Query results are lazy RealmResults< User > queryResults = realm.allObjects(User .class); queryResults.get(0) != queryResults.get(0); // Different Java objects queryResults.get(0).equals(queryResults.get(0)); // Same data