Where to put Sqlite database on iPad

489 Views Asked by At

I'm writing an app for Apple's iPadOS that uses an SQLite database. I'm controlling the DB using FMDB. During my development I'm pointing FMDB to my local Mac development folder so that I can interrogate the DB using SQLiteStudio instead of digging it out of the development folders that Apple XCode defaults to. When I deploy the application I'd like to be able to put it on the iPad where the Apple "Files" app can see it. I'd like to be able to back it up using iTunes like I can the database of another app that I've purchased.

My question is how to configure the database location on the iPad to be able to achieve those goals. Right now in XCode development I point to:

let databaseFolder = "/Users/robertpetruzzelli/Desktop/MyProjects/ManagingYourMoney"

and when I test on the iPad I change the file path to:

let databaseFolder = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString) as String

which works for the app to see the DB on the iPad, but it isn't visible in the Files app...

Any assistance would be greatly appreciated. Bob

1

There are 1 best solutions below

0
rpetruzz On

Well in a round about way I solved my quandry. Using

let databaseFolder = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString) as String

is the right thing to do, but I needed to do the steps in the link below: Deploying SQLite DB to iPad app (via iTunes?)

By doing this I could see my app on my iPad in finder and see the file there. I could copy the file to my Macbook Air and work on anything I wanted to investigate there.