I'm making a framework that needs to load some data from an sqlite
file. It works great on iOS, but on Mac Catalyst it fails to open the file with the following error:
[NavigationDataProvider.swift:37] createDB() - NavigationData has been loaded from path /Users/username/Library/Developer/Xcode/DerivedData/AppName-finyqxyzgukrabcenmuloduaikbf/Build/Products/Debug-maccatalyst/NavigationData.framework/Resources/navdata.sqlite
2021-06-29 15:50:19.857298+0300 AppName[18534:531626] [logging-persist] cannot open file at line 45068 of [d880193994]
It looks like the file doesn't exist, but if i check it manually from the terminal on my Mac, it does indeed exist:
% file /Users/.../navdata.sqlite: SQLite 3.x database, last written using SQLite version 3035005
So is this some kind of permission issue with Mac Catalyst? It shouldn't be, because the file is included in the Framework bundle, yet still it doesn't work. Any ideas please?
I am getting the path like this:
Bundle(for: NavigationDataProvider.self).path(forResource: "navdata", ofType: "sqlite")
I have also tried Bundle.main
without success. I have tried this on both the production version of Xcode and the latest Xcode-beta with the same result.
Found the problem. You cannot directly access sqlite files within the bundle, you have to copy the file out of the bundle first. In hindsight it is pretty obvious as sqlite probably tries to open the file in readwrite mode and that would not work for the file inside the bundle.