Realm

10.50.0

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

What's New

v10.50.0

2024-05-02T23:27:48Z

Drop support for Xcode 14, as it can no longer be used to submit app to the app
store. Xcode 15.1 is now the minimum supported version.

Known Issues

  • Accessing App.currentUser within an App.subscribe callback would lead to a deadlock.

Enhancements

  • Added SyncConfiguration.initialSubscriptions which describes the initial
    subscription configuration that was passed when constructing the
    SyncConfiguration. (#8548)
  • When connecting to multiple server apps, a unique encryption key is used for
    each of the metadata Realms rather than sharing one between them
    (Core #7552).
  • Improve perfomance of IN queries and chained OR equality queries for
    UUID/ObjectId types. (.Net #3566)
  • Added support for updating Atlas Device Sync's base url, in case the need to roam between
    servers (cloud and/or edge server). This API is private and can only be imported using
    @_spi(Private)
    @_spi(RealmSwiftExperimental) import RealmSwift
    
    try await app.updateBaseUrl(to: "https://services.cloud.mongodb.com")
    (#8486).
  • Enable building RealmSwift as a dynamic framework when installing via SPM, which
    lets us supply a privacy manifest. When RealmSwift is built as a static
    library you must supply your own manifest, as Xcode does not build static
    libraries in a way compatible with xcprivacy embedding. Due to some bugs in
    Xcode, this may require manual changes to your project:
    • Targets must now depend on only Realm or RealmSwift. If you use both the
      obj-c and swift API, depending on RealmSwift will let you import Realm.
      Trying to directly depend on both will give the error "Swift package
      target 'Realm' is linked as a static library by 'App' and 'Realm', but
      cannot be built dynamically because there is a package product with the
      same name."
    • To actually build RealmSwift as a dynamic framework, change "Do Not Embed"
      to "Embed & Sign" in the "Frameworks, Libraries, and Embedded Content"
      section on the General tab of your target's settings.
      (#8561).
  • The transferredBytes and transferrableBytes fields on Progress have been deprecated
    in favor of progressEstimate which is a value between 0.0 and 1.0 indicating the estimated
    progress toward the upload/download transfer. (#8476)

Fixed

  • -[RLMUser allSessions] did not include sessions which were currently
    waiting for an access token despite including sessions in other non-active
    states. (Core #7300, since v10.0.0).
  • [RLMApp allUsers] included users which were logged out during the current
    run of the app, but not users which had previously been logged out. It now
    always includes all logged out users. (Core #7300, since v10.0.0).
  • Deleting the active user (via User.delete()) left the active user
    unset rather than selecting another logged-in user as the active user like
    logging out and removing users does. (Core #7300, since v10.23.0).
  • Fixed several issues around copying an encrypted Realm between platforms with
    different page sizes (such as between x86_64 and arm64 Apple platforms):
    • Fixed Assertion failed: new_size % (1ULL << m_page_shift) == 0 when
      opening an encrypted Realm less than 64Mb that was generated on a platform
      with a different page size than the current platform.
      (Core #7322, since v10.42.0)
    • Fixed a DecryptionFailed exception thrown when opening a small (<4k of
      data) Realm generated on a device with a page size of 4k if it was bundled
      and opened on a device with a larger page size (since the beginning).
    • Fixed an issue during a subsequent open of an encrypted Realm for some rare
      allocation patterns when the top ref was within ~50 bytes of the end of a
      page. This could manifest as a DecryptionFailed exception or as an
      assertion: encrypted_file_mapping.hpp:183: Assertion failed: local_ndx < m_page_state.size(). (Core #7319)
  • Schema initialization could hit an assertion failure if the sync client
    applied a downloaded changeset while the Realm file was in the process of
    being opened (#7041, since v10.15.0).
  • The reported download progress for flexible sync Realms was incorrect. It is now replaced by a
    progress estimate, which is derived by the server based on historical data and other heuristics.
    (#8476)

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.3.0.
  • CocoaPods: 1.10 or later.
  • Xcode: 15.1.0-15.3.0.

Internal

  • Upgraded realm-core from v14.5.2 to 14.6.2
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 May 04 2024 07:44:11 GMT-0900 (Hawaii-Aleutian Daylight Time)