is a mobile database

Realm is a replacement for SQLite & Core Data. It can save you thousands of lines of code & weeks of work, and lets you craft amazing new user experiences.

Download for iOS Download for Android

Sign up for our community newsletter to hear about Realm tutorials, events, tips & more!

Groupon Zynga Expensify Hipmunk Intuit Riteaid Sap

Why should I use Realm?

Easy to Use

Realm is not an ORM on top SQLite. Instead it uses its own persistence engine, built for simplicity (& speed). Users tell us they get started with Realm in minutes, port their apps in hours & save weeks on each app.

Cross-Platform

Realm supports both iOS & Android. You can share Realm files across platforms, use the same high-level models for Java, Swift & Objective-C, and write similar business logic on both platforms.

Fast

Thanks to its zero-copy design, Realm is much faster than an ORM, and is often faster than raw SQLite as well. See benchmarks for iOS, Android or read what users have to say on Twitter.

Supported

Get quick, official answers from the company building and maintaining your database. We are answering questions on Github, StackOverflow, Twitter & during monthly office hours.

What does Realm look like?

Realm Objects Look like Regular Objects…

class Dog: RLMObject {
    dynamic var name = ""
    dynamic var age = 0
}

let mydog = Dog()

mydog.name = "Rex"
println("name of dog: \(mydog.name)")
@interface Dog : RLMObject
@property NSString *name;
@property NSInteger age;
@end

Dog *mydog = [[Dog alloc] init];

mydog.name = @"Rex"; 
NSLog(@"Name of dog: %@", mydog.name);
// Just extend your standard POJO from RealmObject:

public class Dog extends RealmObject {
    private String          name;
    private int             age;
    @ignored private int    dontPersistMe;

    // + Standard setters and getters here
}

Offer Easy Persistence…

let realm = RLMRealm.defaultRealm()

realm.transactionWithBlock() {
    realm.addObject(mydog)
}
RLMRealm *realm = [RLMRealm defaultRealm];

[realm transactionWithBlock:^{
    [realm addObject:mydog];
}];
Realm realm = Realm.getInstance(this.getContext());

// Transactions give you easy thread-safety
realm.beginTransaction();
Dog dog = realm.createObject(Dog.class);
dog.setName("Rex");
dog.setAge(3);
realm.commitTransaction();

Can be Queried…

let r = Dog.objectsWhere("age > 8")

// Queries are chainable
let r2 = r.objectsWhere("name contains 'rex'")
RLMResults *r = [Dog objectsWhere:@"age > 8"];
 
// Queries are chainable
r = [r objectsWhere:@"name contains 'rex'"];
// Queries uses Builder pattern to build up the query conditions
RealmResults<Dog> query = realm.where(Dog.class)
                               .greaterThan("age", 8)
                               .findAll();

// Queries are chainable
RealmResults<Dog> allRex = query.where()
                                .contains("name", "rex")
                                .findAll();

Linked to Each Other…

class Person : RLMObject {
    dynamic var name = ""
    dynamic var picture = NSData()
    dynamic var dogs = RLMArray(objectClassName: Dog.className())
}

realm.transactionWithBlock() {
    let person = Person()
    person.name = "Tim"
    person.dogs.addObject(mydog)
}
@interface Person : RLMObject
@property NSString      *name;
@property NSData        *picture;
@property RLMArray<Dog> *dogs;
@end

[realm transactionWithBlock:^{
    RLMPerson *person = [[RLMPerson alloc] init];
    person.name = @"Tim";
    [person.dogs addObject:mydog];
}];
public class Person extends RealmObject {
    private String name;
    private RealmList<Dog> dogs;
}

realm.beginTransaction();
Dog mydog = realm.createObject(Dog.class);
Person person = realm.createObject(Person.class);
person.setName("Tim");
person.getDogs().add(mydog);
realm.commitTransaction();

… And are Easy to Use Across Threads!

dispatch_async(dispatch_queue_create("background", 0)) {
  
  // All Realm instances are thread-confined,
  // but can be easily fetched from any thread
  let results = Dog.objectsWhere("name contains 'rex'")

  // You can also write to a Realm from any thread
  // with full ACID guarantees
}
dispatch_async(dispatch_queue_create("background", 0), ^{
  
  // All Realm instances are thread-confined,
  // but can be easily fetched from any thread
  RLMResults *results = [Dog objectsWhere:@"name contains 'rex'"];

  // You can also write to a Realm from any thread
  // with full ACID guarantees
});
new Thread(new Runnable() {
    public void run() {
        
        // All Realm instances are thread-confined,
        // but can be easily fetched from any thread
        Realm realm = Realm.getInstance(context);
        RealmResults<Dog> dogs = realm.where(Dog.class)
                                      .contains("name", "rex")
                                      .findAll();
                                      
        // You can also write to a Realm from any thread,
        // with full ACID guarantees
    }
}).start();
Download for iOS Download for Android