Search code examples
macosrealm

How can I delete local realm in macOS?


I want to debug my app from scratch so I need to remove its' Realm file. How do I do that in macOS?

(deleting DerivedData, keychain and cleaning did not work)

Thank you!


Solution

  • I have a button with the following code to remove Realm data in Swift 4

    func doDelete() {
        let realmURL = Realm.Configuration.defaultConfiguration.fileURL!
        let realmURLs = [
            realmURL,
            realmURL.appendingPathExtension("lock"),
            realmURL.appendingPathExtension("note"),
            realmURL.appendingPathExtension("management")
        ]
        for URL in realmURLs {
            do {
                try FileManager.default.removeItem(at: URL)
            } catch let error as NSError {
                print(error.localizedDescription)
            }
        }
    }
    

    alternately you can manually remove the database portion using the finder by deleting the folder:

    ~/Library/Application Support/com.company_name.app_name
    

    the bundle identifier (found in the General settings for your app in Xcode) is the last part of the path. The path may vary depending on sandboxing, iOS/macOS and the bundle name.

    Edit

    With sandboxing on the location is

    ~/Library/Containers/com.company_name.app_name