realm /realm-swift
Realm is a mobile database: a replacement for Core Data & SQLite
★ 16,599⑂ 2,230👁 355⑃ 3,199● 5,500▤ 305
+0
Daily
16,599
stars
2,230
forks
355
watchers
3,199
prs
5,500
issues
305
releases
README
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.
swift
// 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
}
// 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.
swift
// 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.
swift
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.
swift
// Generate a random encryption key
var key = Data(count: 64)
_ = key.withUnsafeMutableBytes { Top issues
#1186Add support for cascading deletes77 comments · 2014-12-06#7902Hang risk - thread priority inversion warning (Xcode)46 comments · 2022-08-04#1490Unsupported predicates38 comments · 2015-02-11#1265Add ability to sort RLMResults using a comparison block38 comments · 2014-12-23#7741EXC_BAD_ACCESS in RLMGetThreadLocalCachedRealmForPath33 comments · 2022-04-08#6898Feature Request: Swift Package Manager Precompiled Binaries33 comments · 2020-10-29#3381Consider making initWithValue: a deep copy of the value30 comments · 2016-03-26#1109Abstract Class / Polymorphism Support30 comments · 2014-11-09
Discussions
#8680The Future: Realm is Deprecated/Dead0 comments · 2024-09-09#8657Allow init Query<Model> object0 comments · 2024-07-23#8639iOS app crash as soon as let realm = try! Realm() this executes1 comments · 2024-06-26#8609How to get notification not only with indexes, but with object keys also?1 comments · 2024-06-03#8603Signature issues due to new Privacy manifest requirement1 comments · 2024-05-24#8584RealmSwift - Getting old value in a RealmCollection's observe?0 comments · 2024-05-10#8501How can I migrate from 10.40.1 to 10.47.0?1 comments · 2024-03-05#8480SwiftUI and Realm: path forward1 comments · 2024-02-10
Latest release
v20.0.6 v20.0.6 2026-09-27Fix a few warnings when building with Xcode 27 and updating packaging for Xcode 27. Compatibility Carthage release for Swift is built with Xcode 27. CocoaPods: 1.10 or later. Xcode: 26.1-27.0