Realm database open file

410 views Asked by At

I am working on my mobile app and with that I have been using Realm Database to store the user data. Further I have made a application for mac that is supposed to be able to open a realm file and display the user data from the file (Yes I know I can use Realm Studio for this, but I want to be able to develop my own application to add some features that my client needs). Does anyone know how I can open a realmfile on an mac app and make the realm code to use data from that file to fill out my tableview?

Thanks!

EDIT: Sorry for my unclear question. What I want is a way for realm database to get use data from a different file than the "default.realm" file. I have tried to see trough the documentation on realm.io but I could not figure it out, hope this cleared things up!

1

There are 1 answers

2
Jay On

Based on an edit to the question, I believe the question is how to access a Realm file other than default.realm.

Here's one option; suppose you want to call your realm file todo.realm.

func setRealmFile() {
    var config = Realm.Configuration()

    // Using the default directory, append todo.realm
    config.fileURL = config.fileURL!.deletingLastPathComponent().appendingPathComponent("todo.realm")

    Realm.Configuration.defaultConfiguration = config
}