Xcode 6.2 creates a new simulator path every time the application starts

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

0
source share
1 answer

You should save only the relative path of your content (document, db, ...), because Xcode with iOS8 (I suppose) changes the application folder whenever you create and launch it.

For example, you have your .db file in Documents, so just save the link as "DataBase.db". Then, when you need to access this file, enter the path as:

 let documentsFolder = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0] as String let dbPath = documentsFolder.stringByAppendingPathComponent("Database.db") 
0
source

Source: https://habr.com/ru/post/1241236/


All Articles