0

I'm attempting to create a sqlite DB file within my iOS project. I'm using the code as documented for R/W

let path = NSSearchPathForDirectoriesInDomains(
    .documentDirectory, .userDomainMask, true
).first!

let db = try Connection("\(path)/db.sqlite3")

but I end up with a cannot open file at line 45340 of [d24547a13b].

The closest resource I've found is Why do I get Unable to Open Database file? but the code there seems to be the same as what I have.

edit: More logs

[logging-persist] os_unix.c:45340: (0) open
- Undefined error: 0
2
  • No more in the error message than that? Commented Nov 10, 2021 at 16:29
  • Added the last few lines! Commented Nov 10, 2021 at 19:01

1 Answer 1

2

DB file needs to be created under the documents directory. See Brando Flores' answer: https://stackoverflow.com/a/70514807/346676

do {
    let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
    let dbFile = "\(path.first ?? "")/db.sqlite3"
    print(dbFile)   // show full file path
    db = try Connection(dbFile)
}
catch {
    print(error)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.