Realm

10.52.0

Realm is a mobile database: a replacement for Core Data & SQLite
realm/realm-swift

What's New

v10.52.0

2024-06-18T23:26:04Z

Enhancements

  • Add @ObservedSectionedResults.remove(atOffsets:section:) which adds the ability to
    remove a Realm Object when using onDelete on ForEach in a SwiftUI List.
  • Add support for Xcode 16 beta 1 and fix some of the new warnings. Note that
    this does not yet include full support for Swift 6 language mode
    (#8618).
  • Realm.asyncWrite() and Realm.asyncRefresh() now use the new #isolation
    feature to avoid sendability warnings when building with Xcode 16
    (#8618).
  • Include the originating client reset error message in errors reporting that
    automatic client reset handling failed. (Core #7761)
  • Improve the performance of insertion-heavy write transactions, particularly
    when setting a large number of properties on each object created
    (Core #7734).
  • App now trims trailing slashes from the base url rather than producing
    confusing 404 errors. (Core #7791).

Fixed

  • Deleting a Realm Object used in a @ObservedSectionedResults collection in SwiftUI
    would cause a crash during the diff on the View. (#8294, since v10.29.0)
  • Fix some client resets (such as migrating to flexible sync) potentially
    failing if a new client reset condition (such as rolling back a flexible sync
    migration) occurred before the first one completed.
    (Core #7542, since v10.40.0)
  • The encryption code no longer behaves differently depending on the system
    page size, which should entirely eliminate a recurring source of bugs related
    to copying encrypted Realm files between platforms with different page sizes.
    One known outstanding bug was (RNET-1141),
    where opening files on a system with a larger page size than the writing
    system would attempt to read sections of the file which had never been
    written to (Core #7698).
  • There were several complicated scenarios which could result in stale reads
    from encrypted files in multiprocess scenarios. These were very difficult to
    hit and would typically lead to a crash, either due to an assertion failure
    or DecryptionFailure being thrown (Core #7698, since v10.38.0).
  • Encrypted files have some benign data races where we can memcpy a block of
    memory while another thread is writing to a limited range of it. It is
    logically impossible to ever read from that range when this happens, but
    Thread Sanitizer quite reasonably complains about this. We now perform a
    slower operations when running with TSan which avoids this benign race
    (Core #7698).
  • Realm.asyncOpen() on a flexible sync Realm would sometimes fail to wait for
    pending subscriptions to complete, resulting in it not actually waiting for
    all data to be downloaded. (Core #7720,
    since flexible sync was introduced).
  • List<AnyRealmValue>.clear() would hit an assertion failure when used on a
    file originally created by a version of Realm older than v10.49.0.
    (Core #7771, since 10.49.0)

Compatibility

  • Realm Studio: 15.0.0 or later.
  • APIs are backwards compatible with all previous releases in the 10.x.y series.
  • Carthage release for Swift is built with Xcode 15.4.0.
  • CocoaPods: 1.10 or later.
  • Xcode: 15.1.0-16 beta

Internal

  • Upgraded realm-core from v14.9.0 to 14.10.1
realm by MongoDB

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.
  • MongoDB Atlas Device Sync: Makes it simple to keep data in sync across users, devices, and your backend in real-time. Get started for free with a template application and create the cloud backend.

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 { bytes in
    SecRandomCopyBytes(kSecRandomDefault, 64, bytes)
}

// 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 the detailed instructions in our docs.

Interested in getting started for free with a template application that includes a cloud backend and Sync? Create a MongoDB Atlas Account.

Documentation

The documentation can be found at mongodb.com/docs/atlas/device-sdks/sdk/swift/. The API reference is located at mongodb.com/docs/realm-sdks/swift/latest/

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 14.1 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 community-conduct@mongodb.com.

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!

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

Last updated: Sat Dec 21 2024 21:09:45 GMT-1000 (Hawaii-Aleutian Standard Time)