如何查找Mac App的Realm文件位置 [英] How to find Realm file location of a Mac App
问题描述
首先,我对Realm
生态系统非常陌生.
First of all, I am very new to Realm
ecosystem.
我已经在AppDelegate
的applicationDidFinishLaunching
方法中尝试过
I have tried this in AppDelegate
's applicationDidFinishLaunching
method,
print("Realm Path : \(realm.configuration.fileURL?.absoluteURL)")
但是它给了我一个错误,因为我在realm
对象中添加了一些新属性,这与旧模式产生了冲突,甚至在打印之前就使应用程序崩溃了.
But it gave me error because, I have added some new properties to the realm
object, which produced conflicts with the old schema and crashed the app before even printing this.
如果您对崩溃日志感兴趣.但这与主要问题无关,对吧?
If you are interested in the crash log. But it has nothing to do with the main question, right?
严重错误:尝试!"表达式意外引发错误:Error Domain = io.realm Code = 10由于以下原因,需要迁移 错误: -属性'id'已添加到最新的对象模型中." UserInfo = {NSLocalizedDescription = Migration是必需的,因为 以下错误: -属性"id"已添加到最新的对象模型.,错误代码= 10}:文件 /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-703.0.18.8/src/swift/stdlib/public/core/ErrorType.swift, 第54行
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=10 "Migration is required due to the following errors: - Property 'id' has been added to latest object model." UserInfo={NSLocalizedDescription=Migration is required due to the following errors: - Property 'id' has been added to latest object model., Error Code=10}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-703.0.18.8/src/swift/stdlib/public/core/ErrorType.swift, line 54
我还有一个疑问.我已经添加了此内容,甚至在初始化旧对象之前,域都必须为deleteAll
吗?但是它只是崩溃了上面给出的日志.
I have one more doubt. I have added this, the realm has to deleteAll
before even initialising the old objects right? But it just crashed with the log given above.
import Cocoa
import RealmSwift
import Realm
//MARK: Global Variables
public let realm = try! Realm()
func applicationDidFinishLaunching(aNotification: NSNotification) {
realm.deleteAll()
print("Realm Path : \(realm.configuration.fileURL?.absoluteURL)")
}
所以现在我想删除realm
文件,但是我不知道在哪里可以找到它.我在Mac中使用扩展名.realm
搜索,但是找不到所需的文件.我有Realm browser
应用程序,我以为它会将我重定向到文件位置,但没有,它只是打开了Documents
文件夹,没有领域文件.
So now I want to delete the realm
file, but I have no idea where to find it. I have searched in Mac using extension .realm
, but could not the find the expected file. I have the Realm browser
app, I thought it would redirect me to the file location, but it didn't, it just opened the Documents
folder, there is no realm file.
您将如何做?谢谢前进.
How would you do it? Thanks it advance.
推荐答案
在创建新文件时,Realm
确实发生了变化.
The Realm
does change when you create new file.
只需将以下行添加到您的ViewDidLoad
方法:
Just add the following line to your ViewDidLoad
method:
print(Realm.Configuration.defaultConfiguration.fileURL!)
此行会将位置打印到XCode控制台.复制文件路径,转到Finder
->转到"->转到文件夹..."->粘贴路径,然后单击转到".
This line will print the location to XCode console. Copy the file path, go to Finder
-> Go -> Go go Folder... -> paste the path and hit Go.
这篇关于如何查找Mac App的Realm文件位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!