func preloadDBData() { let sqlitePath = Bundle.main.path(forResource: "MyDB",ofType: "sqlite") let sqlitePath_shm = Bundle.main.path(forResource: "MyDB",ofType: "sqlite-shm") let sqlitePath_wal = Bundle.main.path(forResource: "MyDB",ofType: "sqlite-wal") let URL1 = URL(fileURLWithPath: sqlitePath!) let URL2 = URL(fileURLWithPath: sqlitePath_shm!) let URL3 = URL(fileURLWithPath: sqlitePath_wal!) let URL4 = URL(fileURLWithPath: NSPersistentContainer.defaultDirectoryURL().relativePath + "/MyDB.sqlite") let URL5 = URL(fileURLWithPath: NSPersistentContainer.defaultDirectoryURL().relativePath + "/MyDB.sqlite-shm") let URL6 = URL(fileURLWithPath: NSPersistentContainer.defaultDirectoryURL().relativePath + "/MyDB.sqlite-wal") if !fileManager.default.fileExists(atPath: NSPersistentContainer.defaultDirectoryURL().relativePath + "/MyDB.sqlite") { // copy 3 files do { try fileManager.default.copyItem(at: URL1,to: URL4) try fileManager.default.copyItem(at: URL2,to: URL5) try fileManager.default.copyItem(at: URL3,to: URL6) print("=======================") print("fileS copIED") print("=======================") } catch { print("=======================") print("ERROR IN copY OPERATION") print("=======================") } } else { print("=======================") print("fileS EXIST") print("=======================") }}
现在你可以从AppDelegate的dIDFinishLaunchWithOptions方法调用这个方法,这将预加载我们放在应用程序中的数据库.
总结以上是内存溢出为你收集整理的ios – 如何使用swift 3 xcode 8在核心数据中预加载数据库全部内容,希望文章能够帮你解决ios – 如何使用swift 3 xcode 8在核心数据中预加载数据库所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)