我已经通过领域创建了一个DB,我无法找到文件,因为我的操作系统(Yosemite)在/private/var/mobile中没有移动文件夹。
我应该如何访问我的领域以在浏览器中运行?
交叉张贴从谷歌组
我已经通过领域创建了一个DB,我无法找到文件,因为我的操作系统(Yosemite)在/private/var/mobile中没有移动文件夹。
我应该如何访问我的领域以在浏览器中运行?
交叉张贴从谷歌组
当前回答
正如前面提到的,您可以使用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默认不会打开它
其他回答
我为iOS/macOS找到了最简单的方法 (适用于swift 3 Xcode 8.3)
override func viewDidLoad() {
// for swift 2.0 Xcode 7
print(Realm.Configuration.defaultConfiguration.fileURL!)
}
然后x代码将记录正确的路径,检查下面的屏幕。
现在打开你的Finder并按⌘+ +G (command+shift+G)并粘贴到Xcode上的日志路径
对于那些使用React Native和使用默认域的用户:
Realm.defaultPath
Swift 2.3解决方案
更简单的解决方案,不会打破与领域更新
let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
print("App Path: \(dirPaths)")
realm文件应该在Documents中
虽然这个问题本身是针对iOS系统的,但它的标题却很普通,所以我才来到这里。所以,我觉得有必要在这里分享一个Windows的解决方案。
在dotnet c#中,使用realm. config . databasepath查看域文件的位置。如果没有不同的设置,那么它是C:\Users\<username>\Documents\default。以及default.realm.management文件夹和default.realm.lock
要设置一个新路径,调整这段代码(文件夹必须存在,否则会出错)
var realm = Realm.GetInstance(new RealmConfiguration(optionalPath: "C:/myproject/myrealm/myproject.realm" ));
我所做的就是利用
let realm = Realm(path: "/Users/me/Desktop/TestRealm.realm")
然后它就会在桌面上全屏显示出来,我可以双击打开Realm浏览器。稍后,当我满意一切都按预期工作时,我可以删除参数并让它使用默认位置。