I know there are some resources available for this but none of them clearly show the way how to do it properly.
I have already populated .sqlite database (MTrader.db) and i want to connect it to my swift project and load the data from the database into spinner.
I tried so many ways but it doesn't work. I try to edit lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? method in AppDelegete.swift as
if !NSFileManager.defaultManager().fileExistsAtPath(url.path!) {
let sourceSqliteURLs = [NSBundle.mainBundle().URLForResource("MTrader", withExtension: "db")!]
let destSqliteURLs = [self.applicationDocumentsDirectory.URLByAppendingPathComponent("MTrader.db")]
var error:NSError? = nil
for var index = 0; index < sourceSqliteURLs.count; index++ {
NSFileManager.defaultManager().copyItemAtURL(sourceSqliteURLs[index], toURL: destSqliteURLs[index], error: &error)
}
}
For some reason above code isn't working. I copied my database file in my project. So is there any error with my code or any better way to use my existing database without creating new database and populating it?