我已经通过领域创建了一个DB,我无法找到文件,因为我的操作系统(Yosemite)在/private/var/mobile中没有移动文件夹。

我应该如何访问我的领域以在浏览器中运行?

交叉张贴从谷歌组


当前回答

我所做的就是利用

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

然后它就会在桌面上全屏显示出来,我可以双击打开Realm浏览器。稍后,当我满意一切都按预期工作时,我可以删除参数并让它使用默认位置。

其他回答

我在这方面更进一步。 我已经创建了一个名为RealmFunctions的swift文件,并在其中创建了这个函数

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

现在在我的主视图控制器中,我有一个全局布尔变量叫做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.

现在,我在代码中要做的就是

let realm = realmAndPath()

因此,当处于开发模式时,我可以在桌面上找到我的领域数据库,并可以在领域浏览器中打开。

如果你在模拟器中使用默认的Realm DB:

po Realm().configuration.fileURL

正如前面提到的,您可以使用next方法来查找文件位置

//code
Realm.Configuration.defaultConfiguration.fileURL 

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

或者你可以手动找到它:

//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

*请注意,如果你为realm设置了文件名,并且它有一些其他扩展名而不是。realm, RealmStudio默认不会打开它

我通过在终端中执行以下命令找到了我的域文件: Sudo find / -name "*.realm"。

希望这能有所帮助!

首先,我承认这是一个Android线程,但这是这个问题的第一个搜索结果。

要在Realm Browser中打开最近创建的Xcode Simulator Realm db,你可以在Automator中使用这个脚本,或者在终端中全部输入。通过使用Automator,我可以一键访问我的当前领域。

    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

安装Realm浏览器。 在Automator中,单击新建,选择运行Shell脚本,粘贴代码,更改Realm Db名称,单击运行测试,将文件保存到方便快速点击访问的地方。

我不知道我第一次在哪里找到这个技巧,但这个帖子提醒了我过去是如何访问我的实时数据的。