You can transfer your realm object to your edit view controller as an object in memory for editing. For instance:
RLMRealm *realm = [RLMRealm defaultRealm]; [realm beginWriteTransaction]; [StringObject createInDefaultRealmWithObject:@[@"a"]]; [realm commitWriteTransaction]; StringObject *obj = [[StringObject alloc] initWithObject:[[StringObject allObjects] firstObject]]; XCTAssertEqualObjects(obj.stringCol, @"a"); obj.stringCol = @"b"; // not in a write transaction XCTAssertEqualObjects(obj.stringCol, @"b");
If the user clicks "Save", you can call createOrUpdateInDefaultRealmWithObject: and pass your object in memory, which will then pass all the values ββand update this object in Realm. Note that your object must have a primary key for this.
If the user clicks Cancel, you can simply discard this object in memory as if nothing had happened.
Please note that in the future we intend to add transaction rollback functionality, which will simplify this template.
jpsim source share