How create a URL to device store on iOS simulator

不羁的心 提交于 2019-12-11 17:08:33

问题


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")


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/51844633/how-create-a-url-to-device-store-on-ios-simulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!