realm-swift is a free, open source databases project written in Objective-C and released under Apache-2.0. It has 16,609 GitHub stars, 2,241 forks and 499 open issues, and was last pushed 2 days ago. On this registry it ranks #44 of 143 tracked projects in Databases, with 5 head-to-head comparisons available.

What is realm-swift?

Realm Database is a mobile database that runs directly inside phones, tablets, and wearables, and it is for iOS, macOS, tvOS, and watchOS developers who need a replacement for Core Data and SQLite.

What it is

Realm Database runs in-process on the device. This repository holds source for the iOS, macOS, tvOS, and watchOS builds of Realm Swift and Realm Objective-C. Data model is object-oriented: declare classes that subclass Object, mark fields with @Persisted, set primaryKey where needed, and build relationships by pointing List fields at other classes. No ORM sits between code and store. Persistence happens through realm.write on a realm opened with try! Realm().

The problem it solves is local persistence for mobile apps. Core Data forces managed object graphs and boilerplate; SQLite forces hand-written SQL plus a mapping layer. Realm replaces both with plain classes and a write transaction. Data lives on disk, so an app behaves the same offline as online. Live objects mean a change made anywhere is reflected everywhere, which removes manual refresh code from view layers. The project lives in the Apple-platform ecosystem, spanning Swift, Objective-C, and SwiftUI.

Key capabilities

  • Object-oriented model using Object, @Persisted, primaryKey, and List relationships, with no ORM required.
  • Live objects with change notifications: attach observe and watch a NotificationToken report .change, .error, or .deleted.
  • Direct SwiftUI integration via @ObservedResults, which updates views automatically, including onMove and onDelete on result collections.
  • Encryption at-rest and in-flight, configured by passing a 64-byte encryptionKey to Realm.Configuration; the README generates that key with SecRandomCopyBytes.
  • Offline-first operation, with the local database persisting on-disk so apps work as well offline as online.
  • Thread-safe access and realtime/sync support, per the repository topic list.
  • Query support through realm.objects(Dog.self).filter(...), as in the README encryption sample.

Who uses it and how

  • iOS, macOS, tvOS, and watchOS teams that want on-device persistence without Core Data managed object graphs or SQLite mapping code.
  • SwiftUI apps that need lists and detail views to react to data changes without hand-written refresh logic.
  • Mobile apps handling sensitive local data that require encrypted storage and encrypted transfer.
  • Offline-first products where the network is unreliable and the app must keep working against a local store.
  • Developers seeking help through the realm tag on Stack Overflow or the MongoDB community forum, the two support channels the README names.

Getting started

Install through Swift Package Manager, CocoaPods, Carthage, or by importing a dynamic XCFramework. The Quick Start lives at docs/guides/quick-start.md, and the API reference is generated with jazzy by running sh build.sh docs from the repository root.

How it compares

The two named alternatives are Core Data and SQLite, the things this project exists to replace. Against Core Data, Realm offers an object model that needs no managed object context, and against SQLite it offers typed objects instead of raw SQL plus a separate mapping layer. Realm ships under Apache-2.0 as a library linked into the app, so there is no server to run for the on-device use case.

When to use it — and when not to

Pick Realm when the target platforms are Apple-only and the app needs fast local persistence with reactive updates. Do not pick it for non-Apple platforms, since this repository covers only iOS, macOS, tvOS, and watchOS, and do not pick it if the team wants direct SQL access to the store. Note the 499 open issues and that the README documents the SDK only: the topic list mentions sync, but the excerpt does not describe any server deployment or operational requirements, so verify that side separately before committing.

project readme (upstream, from github) — read inline

About Realm Database

Realm is a mobile database that runs directly inside phones, tablets or wearables. This repository holds the source code for the iOS, macOS, tvOS & watchOS versions of Realm Swift & Realm Objective-C.

Why Use Realm

  • Intuitive to Developers: Realm’s object-oriented data model is simple to learn, doesn’t need an ORM, and lets you write less code.
  • Built for Mobile: Realm is fully-featured, lightweight, and efficiently uses memory, disk space, and battery life.
  • Designed for Offline Use: Realm’s local database persists data on-disk, so apps work as well offline as they do online.

Object-Oriented: Streamline Your Code

Realm was built for mobile developers, with simplicity in mind. The idiomatic, object-oriented data model can save you thousands of lines of code.

// Define your models like regular Swift classes
class Dog: Object {
    @Persisted var name: String
    @Persisted var age: Int
}
class Person: Object {
    @Persisted(primaryKey: true) var _id: String
    @Persisted var name: String
    @Persisted var age: Int
    // Create relationships by pointing an Object field to another Class
    @Persisted var dogs: List<Dog>
}
// Use them like regular Swift objects
let dog = Dog()
dog.name = "Rex"
dog.age = 1
print("name of dog: \(dog.name)")

// Get the default Realm
let realm = try! Realm()
// Persist your data easily with a write transaction
try! realm.write {
    realm.add(dog)
}

Live Objects: Build Reactive Apps

Realm’s live objects mean data updated anywhere is automatically updated everywhere.

// Open the default realm.
let realm = try! Realm()

var token: NotificationToken?

let dog = Dog()
dog.name = "Max"

// Create a dog in the realm.
try! realm.write {
    realm.add(dog)
}

//  Set up the listener & observe object notifications.
token = dog.observe { change in
    switch change {
    case .change(let properties):
        for property in properties {
            print("Property '\(property.name)' changed to '\(property.newValue!)'");
        }
    case .error(let error):
        print("An error occurred: (error)")
    case .deleted:
        print("The object was deleted.")
    }
}

// Update the dog's name to see the effect.
try! realm.write {
    dog.name = "Wolfie"
}

SwiftUI

Realm integrates directly with SwiftUI, updating your views so you don't have to.

struct ContactsView: View {
    @ObservedResults(Person.self) var persons

    var body: some View {
        List {
            ForEach(persons) { person in
                Text(person.name)
            }
            .onMove(perform: $persons.move)
            .onDelete(perform: $persons.remove)
        }.navigationBarItems(trailing:
            Button("Add") {
                $persons.append(Person())
            }
        )
    }
}

Fully Encrypted

Data can be encrypted in-flight and at-rest, keeping even the most sensitive data secure.

// Generate a random encryption key
var key = Data(count: 64)
_ = key.withUnsafeMutableBytes { (pointer: UnsafeMutableRawBufferPointer) in
    guard let baseAddress = pointer.baseAddress else {
        fatalError("Failed to obtain base address")
    }
    SecRandomCopyBytes(kSecRandomDefault, 64, baseAddress)
}

// Add the encryption key to the config and open the realm
let config = Realm.Configuration(encryptionKey: key)
let realm = try Realm(configuration: config)

// Use the Realm as normal
let dogs = realm.objects(Dog.self).filter("name contains 'Fido'")

Getting Started

We support installing Realm via Swift Package Manager, CocoaPods, Carthage, or by importing a dynamic XCFramework.

For more information, see our Quick Start.

Documentation

The documentation can be found in the docs/ directory.

The API reference can be generated from source using jazzy by running sh build.sh docs from the root of this repository.

Getting Help

  • Need help with your code?: Look for previous questions with therealm tag on Stack Overflow or ask a new question. For general discussion that might be considered too broad for Stack Overflow, use the Community Forum.
  • Have a bug to report? Open a GitHub issue. If possible, include the version of Realm, a full log, the Realm file, and a project that shows the issue.
  • Have a feature request? Open a GitHub issue. Tell us what the feature should do and why you want the feature.

Building Realm

In case you don't want to use the precompiled version, you can build Realm yourself from source.

Prerequisites:

  • Building Realm requires Xcode 15.3 or newer.
  • Building Realm documentation requires jazzy

Once you have all the necessary prerequisites, building Realm just takes a single command: sh build.sh build. You'll need an internet connection the first time you build Realm to download the core binary. This will produce Realm.xcframework and RealmSwift.xcframework in build/Release/.

Run sh build.sh help to see all the actions you can perform (build ios/osx, generate docs, test, etc.).

Contributing

See CONTRIBUTING.md for more details!

Code of Conduct

This project adheres to the MongoDB Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected].

License

Realm Objective-C & Realm Swift are published under the Apache 2.0 license. Realm Core is also published under the Apache 2.0 license and is available here.

Feedback

If you use Realm and are happy with it, please consider sending out a tweet mentioning @realm to share your thoughts!

And if you don't like it, please let us know what you would like improved, so we can fix it!

Frequently asked questions

Is realm-swift free to use?

realm-swift is open source under the Apache-2.0 licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does realm-swift do?

Realm is a mobile database: a replacement for Core Data & SQLite

What is realm-swift written in?

realm-swift is primarily written in Objective-C. Its source is publicly available at https://github.com/realm/realm-swift, and it has 16,609 GitHub stars.