269

I have created a DB by realm and I am not able to find the file as my OS (Yosemite) dont have a mobile folder in the /private/var/mobile.

How should I access my realm to run in the browser?

Cross posted from google groups

1
  • Check this out. This method works for both rooted and unrooted devices.
    – krhitesh
    Apr 7, 2018 at 8:48

26 Answers 26

507

Finding a Realm File

For Android

How to view my Realm file in the Realm Browser?

For iOS

If your App is on Device

Make sure that your device is connected and go to the devices window in the Xcode menu Window > Devices (⌘⇧2). There you will be able to choose your device and your app from a list of installed apps with debugging permissions.

After selecting your app, go to the cog in the toolbar at the bottom of the table view and select “Download Container…“. There you will be able to pull the file from the documents location to your Mac. It will be saved as an xcappdata bundle.

When you open the local path in Finder, where you saved it, you can tap into that by selecting “Show Package Contents” in the context menu of the finder, when you select the file. A new finder window will open, where you find your Realm inside in the following path (e.g.): AppData/Documents/default.realm (The directory '/private/var/mobile' is the path, which is used by iOS on the device filesystem.

If your App is on the Simulator

Go to your user’s directory:

/Users/<username>/Library/Developer/CoreSimulator/Devices/<simulator-uuid>/data/Containers/Data/Application/<application-uuid>/Documents/default.realm

Probably the easiest way to get the current path of the default realm is to pause the simulator and enter the following into the LLDB console:

Objective-C:
(lldb) po [RLMRealmConfiguration defaultConfiguration].fileURL

Swift using Realm Objective-C:
(lldb) po RLMRealmConfiguration.defaultConfiguration().fileURL

Swift using Realm Swift:
(lldb) po Realm.Configuration.defaultConfiguration.fileURL

Or if you have an RLMRealm instance at hand, you can use:
(lldb) po myRealm.configuration.fileURL

Then just copy this path, open your terminal, and type open [Pasted path here]

NOTE: Some paths have a space in them so be sure to use "\" before the space to escape it

Helper Tool SimPholders

This is probably the fastest way to find the file of an app in the simulator. Install SimPholders. This will allow you to access your app’s documents directory directly from your menu bar.

Note Some people have mentioned that SimPholders has taken them to the wrong simulator app folder, if that's the case for you, print out your realm path by following the steps above, printing out your realm.path

12
  • 1
    after the latest update there is a error when u do po RLMRealm.defaultRealmPath(). It says called object type 'NSString *' is not a function or function pointer
    – carbonr
    Jun 1, 2015 at 12:55
  • I have the same issue as @carbonr. Can anybody help?
    – denislexic
    Jun 16, 2015 at 20:35
  • 2
    Objective-C version above 0.97 use po [[RLMRealm defaultRealm]path]
    – AlexHsieh
    Jan 26, 2016 at 10:20
  • 5
    Part of this answer is outdated now. Here is most recent way to find your realm database file (default.realm) using RealmSwift: Realm.Configuration.defaultConfiguration.fileURL
    – nodebase
    Apr 30, 2016 at 18:51
  • 2
    Using the RealmSwift method I get the following: error: use of undeclared identifier 'Realm' Feb 17, 2017 at 16:14
140

I found most simplest way for iOS/macOS (for swift 3 Xcode 8.3)

override func viewDidLoad() {

   // for swift 2.0 Xcode 7
   print(Realm.Configuration.defaultConfiguration.fileURL!)
}

Then x code will log the correct path, check the screen below.

enter image description here

Now open your Finder and press + + G (command+shift+G) and paste the path that logs on your Xcode

6
  • 12
    path is deprecated. use Realm.Configuration.defaultConfiguration.fileURL instead
    – hewigovens
    Apr 28, 2016 at 8:10
  • 2
    Its been changed to Realm.configuration.fileURL
    – Reshad
    Jun 22, 2016 at 12:45
  • 3
    swift 3, xcode8.3 also works with Realm.Configuration.defaultConfiguration.fileURL!
    – xmhafiz
    Jun 5, 2017 at 8:52
  • 1
    This solution works only with Simulator and not with real devices.
    – AndaluZ
    Sep 6, 2018 at 12:47
  • 1
    This is perfect for simulator and once you find your file, it is an easy cmd-click to "Open WIth" to fire up Realm Studio. This begs the question or thought: Realm Studio needs an "open recent" File menu option!
    – drew..
    Nov 24, 2018 at 19:46
45

One Easy Alternative For Simulator Apps

Create a smart folder/search in Finder. Gives quick and easy clickable access to all your realm files.

  1. Open the folder /Users/$USER/Library/Developer/CoreSimulator/Devices in Finder.

    With terminal open /Users/$USER/Library/Developer/CoreSimulator/Devices

  2. Search for .realm

  3. Change the search to look in the "Devices" folder only.

  1. Save the search to your sidebar (e.g. as Realms)

When sorted by date this will give you a quick and easy clickable list of the latest modified Simulator .realm files.

3
  • Thanks @Archdoog - not a bad idea when you're going through lots of new projects with Realm
    – Allen
    Jan 6, 2018 at 23:42
  • 6
    Saving it as a search is genius! Thank you! :)
    – karlingen
    Jul 11, 2018 at 6:24
  • realm can also be searched for using cd ~/Library/Developer/CoreSimulator/Devices && find . -name '*.realm'
    – a2f0
    Nov 23, 2020 at 15:47
22

Here is an easy solution.. I messed with this for awhile. I should point out, this is a specific set of instructions using Android Studio and the AVD Emulator.

1) Start the Emulator and run your app.

2) While the app is still running, open the Android Device Monitor. (its in the toolbar next to the AVD and SDK manager icons)

3) Click the File Explorer tab in the Device Monitor. There should be a lot of folders.

4) Navigate the following path: Data > Data > Your Package Name > files > Default.Realm (or whatever you named it)

Ex. If you are using one of the realm example projects, the path would be something like Data>Data>io.realm.examples.realmgridview>files>default.realm

5) Highlight the file, click the Floppy Disk icon in the upper right area "pull a file from the device"

6) Save it off to whereever you want and done.

0
19

What I did was to use

let realm = Realm(path: "/Users/me/Desktop/TestRealm.realm")

and then it gets created in full view on my desktop and I can double-click to launch the Realm Browser on it. Later, I can remove the parameter and let it use the default location when I'm satisfied that all is working as expected.

4
  • 1
    I get an error saying " Argument labels '(path:)' do not match any available overloads ". Any idea why? Dec 19, 2016 at 15:09
  • Thats just amazing haha!
    – WilomGfx
    Mar 9, 2017 at 15:57
  • Great for testing on the simulator, but probably won't work correctly on a real device. Sep 26, 2017 at 6:39
  • let realm = try! Realm(fileURL: URL(string: "/Users/[me]/Desktop/TestRealm.realm")!)
    – Elijah
    Nov 12, 2017 at 21:11
13

The above answers missing a way to find the realm file in Android platform and believe me this way will save your lot's of time which we generally waste in other approaches to get the realm file. So let's start...

First open "Device File Explorer" in android studio(View -> Tools Windows -> Device File Explorer.

This will open your device explorer.

enter image description here

now open data -> data -> (your_app_package_name) -> files -> default.realm

default.realm is the file for which we are here. Now Save_as this file at your location and access the file from the realm_browser and you will get your database.

NOTE: Mentioned approach is tested on non-rooted phone(one+3).

11

Objective-C - [RLMRealmConfiguration defaultConfiguration].fileURL

NSLog(@"%@",[RLMRealmConfiguration defaultConfiguration].fileURL);

Eg-/Users/"Your-user-name"/Library/Developer/CoreSimulator/Devices/E58645FF-90DE-434D-B2EB-FA145EB6F2EA/data/Containers/Data/Application/E427BD21-2CB1-4F64-9ADF-8742FF731209/Documents/

This is the simplest command you can run to get your path to .realm file. You will see the .realm file after all your read and write operations are completed.

Or

You can you open source openSim, alternative of simpholders to access your app’s documents directory directly from your menu bar

10

If you are using the default Realm DB in simulator:

po Realm().configuration.fileURL
2
  • Can you add some details?
    – zeeshan
    Mar 16, 2019 at 13:59
  • @zeeshan please pause your simulator while running, and type the command in, then press enter. Mar 16, 2019 at 19:05
9

Updated answer to the newest Realm:

For Android:

checkout stetho and https://github.com/uPhyca/stetho-realm Video tutorial here: https://www.youtube.com/watch?v=9pFJz5VexRw

For IOS (Swift)

Either:

debugPrint("Path to realm file: " + realm.configuration.fileURL!.absoluteString)

or

Step 1: Have a constant called dev somewhere. Let's say Constant file

public class Constants {

    public static var dev: Bool = true

}

Step 2: Create another class called RealmFunctions.swift

import RealmSwift


func realmAndPath() -> Realm {
    if Constants.dev {
        // location of my desktop
        let testRealmURL = NSURL(fileURLWithPath: "/Users/#####/Desktop/TestRealm.realm")
        return try! Realm(fileURL: testRealmURL)
    } else {
        return try! Realm()
    }
}

Step 3: finally in your view controller:

let realm = realmAndPath()

thanks to Stewart Lynch for the original answer

1
  • for swift 3 i needed to change realm.path to realm.configuration.fileURL!.absoluteString
    – Andrew
    Oct 20, 2016 at 0:10
5

If you are getting 'Enter Encryption Key' dialog box error:

I am using Swift 2.1 with Realm 0.96.2 and was getting this error when trying to open the database file:

'default' could not be opened. It may be encrypted, or it isn't in a compatible file format. If you know the file is encrypted, you can manually enter its encryption key to open it.

Found that using the pre-release version of the Realm Browser 0.96 fixed the issue:

https://github.com/realm/realm-browser-osx/releases/tag/0.96-prerelease

5

2020: Realm file on iOS Real device (Not simulator)

Starts from the menu bar at the top then follow the sequence below: -

  1. Window

  2. Devices and Simulators

  3. Select Device

  4. At the bottom find the title (INSTALLED APPS)

    Note: Scroll down or enlarge the Devices and simulators pop up window to see the list of installed apps.

  5. Select Your app.

  6. Tap the gear button (It's located at the bottom of the apps list)

  7. Download Container

  8. Choose location to save it.

  9. Right click on the downloaded file

  10. Show Package contents

  11. AppData

That's it from there you can access Your Realm files depending on your configuration. For example if you saved in Documents or Library folders simply open it to see your realms.

0
3

I found my realm file by issuing this command in Terminal: sudo find / -name "*.realm".

Hope this helps!

3

First, I acknowledge that this is an Android thread but it is the first search result for this issue in general.

To open the most recently created Xcode Simulator Realm db in Realm Browser you can use this script in Automator or type it all in at the terminal. By using Automator, I have one-click access to my current realm.

    cd ~/Library/Developer/CoreSimulator/Devices/
    cd `ls -t | head -n 1`/data/Containers/Data/Application
    cd `ls -t | head -n 1`/Documents    
    open -a 'Realm Browser' ./default.realm

Install Realm Browser. In Automator, click New, select Run Shell Script, paste in code, change Realm Db name, Click Run to test, save file somewhere convenient for quick click access.

I don't know where I found this tip the first time but this thread reminded me how I was accessing my live data in the past.

3

Just for your App is on the iOS Simulator

Enter

console.log (Realm.defaultPath)

in the code eg: App.js

0
3

As previously was mentioned you can use next approaches to find file location

//code
Realm.Configuration.defaultConfiguration.fileURL 

//lldb
(lldb) po Realm.Configuration.defaultConfiguration.fileURL

or you can manually find it:

//Simulator
/Users/<username>/Library/Developer/CoreSimulator/Devices/<simulator-uuid>/data/Containers/Data/Application/<application-uuid>/Documents/

//for example
/Users/alex/Library/Developer/CoreSimulator/Devices/E1D084B0-CD97-41B4-871F-E131CA33F635/data/Containers/Data/Application/373721C7-2381-4E3D-9ABC-2147F748322F/Documents/

//iPhone (download a copy)
Xcode -> Window -> Devices and Simulators -> Devices -> <select device and app> -> App container actions -> Download Container... -> <selectfolder and navigate to it (.xcappdata)> -> Right Click -> Show Package Consents -> AppData -> Documents

*Please note that if you set file name for realm and it has some other extension than .realm RealmStudio does not open it by default

2

I have taken this one step further. I have created a swift file called RealmFunctions and in it, I have created this function

    import RealmSwift
    func realmAndPath() -> Realm {
        if dev {
            // location of my desktop
            return try! Realm(path: "/Users/slynch/Desktop/TestRealm.realm")
        } else {
            return try! Realm()
        }
    }

Now in my main view controller, I have a global boolean variable called dev

var dev: Bool = true // when in development mode
var dev: Bool = false // when I want to run on my device or upload to app stor.

Now, all I have to do in my code is

let realm = realmAndPath()

So when in development mode, I can find my realm database on my desktop and can open in Realm Browser.

1
  • 1
    Error:(13, 21) argument labels '(path:)' do not match any available overloads, seems it changed in the newer versions
    – OWADVL
    Jul 29, 2016 at 9:03
2

For those using React Native and using the default realm:

Realm.defaultPath

5
  • I can not find this!
    – Ali Hesari
    Jun 14, 2018 at 12:59
  • @Natividad where to put this code ? any suggestions on getting realm file? Apr 12, 2019 at 6:27
  • @AliHesari did you find sth ? Apr 12, 2019 at 6:28
  • 1
    componentDidMount() { console.log(Realm.defaultPath) } in my component using Realm worked for me. Check xcode console for path afterwards. Feb 2, 2020 at 0:09
  • In a function component I place it after Realm.open(config) for example like this console.log('* REALM PATH: ' + Realm.defaultPath);
    – ChrisW
    Jul 23, 2021 at 6:50
2

In Swift

func getFilePath() -> URL? {
    let realm = try! Realm()
    return realm.configuration.fileURL
}
2

If you are trying to find your realm file from real iOS device

Worked for me in Xcode 12

Steps -

  1. In Xcode, go to Window -> Devices and Simulators
  2. Select your device from the left side list
  3. Select your app name under the Installed apps section
  4. Now, highlight your app name and click on the gear icon below it
  5. from the dropdown select the Download Container option
  6. Select the location where you want to save the file
  7. Right-click on the file which you just saved and select Show Package Contents
  8. Inside the App Data folder navigate to the folder where you saved your file.
1
  • This seems outdated, as in XCode 12.4 there is no list of installed apps in the Simulators/device section Jul 30, 2021 at 13:39
1

To get the DB path for iOS, the simplest way is to:

  1. Launch your app in a simulator
  2. Pause it at any time in the debugger
  3. Go to the console (where you have (lldb)) and type: po RLMRealm.defaultRealmPath

Tada...you have the path to your realm database

1

The correct (lldb) command is: Realm.Configuration.defaultConfiguration.path.

0

Under Tools -> Android Device Monitor

And under File Explorer. Search for the apps. And the file is under data/data.

0

The correct lldb command for Xcode 7, Swift 2.2+ is po Realm.Configuration.defaultConfiguration.path!

2
  • 1
    the member is not call path but fileURL : Realm.Configuration.defaultConfiguration.fileURL!
    – nburk
    Jun 28, 2016 at 18:03
  • 1
    you are correct...this changed in realm1.0...i was using version 0.98 when i answered this...correct answer is po Realm.Configuration.defaultConfiguration.fileURL?.path
    – Marquis103
    Jun 30, 2016 at 2:12
0

Swift 2.3 solution

Easier solution that won't break with Realm updates

    let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
    print("App Path: \(dirPaths)")

The .realm file should be inside "Documents"

0

all the steps for android and ios can be found on the official realm website: https://support.realm.io/support/solutions/articles/36000064525-how-do-i-locate-realm-files-on-a-device-or-simulator-

0

Although the question itself is for iOS, the title is pretty generic as such that it got me here. So, I have felt the need to share a solution for Windows here.

In dotnet C#, use realm.Config.DatabasePath to see where the realm file is located. If not set differently, then it is C:\Users\<username>\Documents\default.realm along with default.realm.management folder and default.realm.lock

To set a new path, adapt this code (folders must exists, or gives error)

var realm = Realm.GetInstance(new RealmConfiguration(optionalPath: "C:/myproject/myrealm/myproject.realm" ));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.