0

I'm using SQLite.swift library in my iOS app for database needs. I'm using more than one database with different names. I'm doing it fine no problems. At one point I need to delete the .sqlite3 file i.e., the whole database file when it's no longer needed. I'm a newbie to Swift3. So I don't know how to delete the database. My app has a database called AccountsDB to store the number of profiles. Each profile has a database with it's name. When user deletes one profile I need to delete the database with that name too. This is my scenario. Please guide me to achieve my task. Thanks.

Praveen Kumar
  • 547
  • 1
  • 7
  • 33

1 Answers1

1

Use FileManager to delete the physical file from your device. I assume you know (or can retrieve) the path to the SQLite DB file, right? In that case, if url is the file URL to your file:

let fm = FileManager.default
do {
    try fm.removeItem(at:url)
} catch {
    NSLog("Error deleting file: \(url)")
}
Fahim
  • 3,466
  • 1
  • 12
  • 18