Access Realm in Realtime for a React Native App on iOS

Spread the love

If you’re running your app in one of Xcode’s simulators, then the Realm files are stored in your Mac’s file system. They’re typically somewhere along the lines of ~/Library/Developer/CoreSimulator/Devices/???????/data/Containers/Data/Application/???????/Documents/mongodb-realm/???????/????????/???????.realm.

While my app’s in development, I’ll normally print the location of a Realm’s file whenever I open it. Don’t worry if you’re not explicitly opening your Realm(s) in your code (e.g., if you’re using the default realm) as I’ll cover the file search approach soon. This is the code to add to your app once you’ve opened your realm – realm:

print("User Realm User file location: \\(realm.configuration.fileURL!.path)")

If you don’t want to edit the code, then an Xcode breakpoint delivers the same result:

Once you have the file location, open it in Realm Studio from the terminal:

open /Users/andrew.morgan/Library/Developer/CoreSimulator/Devices/E7526AFE-E886-490A-8085-349C8E8EDC5B/data/Containers/Data/Application/C3ADE2F2-ABF0-4BD0-9F47-F21894E850DB/Documents/mongodb-realm/rchat-saxgm/60099aefb33c57e9a9828d23/%22user%3D60099aefb33c57e9a9828d23%22.realm

Less scientific but simpler is to take advantage of the fact that the data files will always be of type realm and located somewhere under ~/Library/Developer/CoreSimulator/Devices. Open Finder in that folder: open ~/Library/Developer/CoreSimulator/Devices and then create a “saved search” so that you can always find all of your realm files. You’ll most often be looking for the most recent one.

The nice thing about this approach is that you only need to create the search once. Then click on “Realms,” find the file you need, and then double-click it to open it in Realm Studio.