I used swiftData to store information in the sqlite database until today, it will work fine, and suddenly it created a new database location, as well as the location of the simulator when it first starts, it shows
/Users/div/Library/Developer/CoreSimulator/Devices/606D7F8E-2402-4782-ADEE-12725EDB203A/data/Containers/Data/Application/2DB733AF-2544-4256-B1E5-5E8725E51CDF/Documents/DataBase.db
second time
/Users/div/Library/Developer/CoreSimulator/Devices/606D7F8E-2402-4782-ADEE-12725EDB203A/data/Containers/Data/Application/551991FA-392A-40E9-810E-31CEFCD3069A/Documents/dataBase.db
third time
/Users/div/Library/Developer/CoreSimulator/Devices/606D7F8E-2402-4782-ADEE-12725EDB203A/data/Containers/Data/Application/03E4BE03-D6E7-47BF-A98D-A129DF09DD28/Documents/DataBase.db
I used this code
let fileManager = NSFileManager() var Sourcepath = NSBundle.mainBundle().resourcePath?.stringByAppendingPathComponent("PhotoKeeper.db"); let docsPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0] as String let databaseStr = "DataBase.db" let dbPath = docsPath.stringByAppendingPathComponent(databaseStr) println(dbPath) if(fileManager .fileExistsAtPath(dbPath) == false) { var error:NSError? fileManager.copyItemAtPath(Sourcepath!, toPath: dbPath, error: &error) println(error) }
my problem occurs every time a new database instance is created, i.e. if I insert 2 lines and compile and run the application, it will create a new database with a zero line
source share