简体   繁体   中英

How create a URL to device store on iOS simulator

I'm using a SQLite to store data on my application. To view my data I need access the simulator store and execute the querys. The path to my simulators change every time that I install the app on iOS simulator. for example a path is:

/Users/augustosansoncadini/Library/Developer/CoreSimulator/Devices/56B6ED1A-8B79-4D5C-836D-D813EEA9FE2F/data/Containers/Data/Application/E7A7BCBD-53FE-4C84-8685-7EA1896694FF/Documents

When I create the SQLite context, I put in this path:

static let fileUrl = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true).appendingPathComponent("Database.sqlite3")

So, Database.sqlite3 is stored on the documents folder of application folder. But the name of app change when I reinstall app.

Like I need access often this file, I created a Alias to navigate to this folder, but the Alias not works because the code of the app changes, so I wants to create a database file in the Store of iOS simulator but I don't know what path I must put in this line:

static let fileUrl = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true).appendingPathComponent("Database.sqlite3")

By "I reinstall app." you mean that you delete from the simulator device and then install it again? or you mean when you re-run the app?

If it's the second one then you will never find your database since you deleted it along with the app.

I think what you really need is a SQLite editor that can handle file path changes automatically, so you needn't have to worry about what the path actually changes to, right?

If the answer is yes, then give SQLiteFlow a try, it's available on App Store, and from it's documentation, it says:

Handle database file name or directory changes. This makes SQLiteFlow can work friendly with your SQLite database in iOS simulator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM