Search code examples
iosswiftrealmios-app-group

Can I share iOS Realm Databases with App Groups?


Can I share iOS Realm Databases with App Groups? If yes, how? If not, how can I share my Realm Database to my other apps?


Solution

  • To share Realms between apps in the same iOS app group, you'll need to specify a common location for the Realm:

    let fileURL = FileManager.default
        .containerURL(forSecurityApplicationGroupIdentifier: "group.io.realm.app_group")!
        .appendingPathComponent("default.realm")
    let config = Realm.Configuration(fileURL: fileURL)
    let realm = try Realm(configuration: config)