8

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.

Idan
  • 5,405
  • 7
  • 35
  • 52
  • realm provide resetting realm if migration needed Realm.Configuration.defaultConfiguration.deleteRealmIfMigrationNeeded = true – Ali Kıran Jul 09 '16 at 12:04

3 Answers3

8

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.

Idan
  • 5,405
  • 7
  • 35
  • 52
1

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

0

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