Reputation:
First of all, I am very new to Realm
ecosystem.
I have tried this in AppDelegate
's applicationDidFinishLaunching
method,
print("Realm Path : \(realm.configuration.fileURL?.absoluteURL)")
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?
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
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)")
}
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.
Upvotes: 8
Views: 3374
Reputation: 11
In case anyone is looking for it, I couldn't find the file in any of the locations above.
I'm on macOS 11.1 and the default.realm file is actually located under
~/Library/Containers/{app.bundle.identifier}/Data/Library/Application Support
Upvotes: 1
Reputation: 5450
The Realm
does change when you create new file.
Just add the following line to your ViewDidLoad
method:
print(Realm.Configuration.defaultConfiguration.fileURL!)
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.
Upvotes: 10
Reputation:
I found the answer to my own question, Happiness :) It will be in this directory.
Users/UserName/Library/Application Support/appBundleIdentifer/default.realm)
Basically username stands for your computer's main users name, and the bundle identifier stands for something like this in your project com.yourCompany.yourApp
Upvotes: 1