java [iOS]复制预先填充的SQLite文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java [iOS]复制预先填充的SQLite文件相关的知识,希望对你有一定的参考价值。

//Copy a pre-populated SQLite file to documents directory for Core Data using Swift
/*
Here is a quick snippet that shows how to check for the existence of a sqlite file in the documents directory and how to copy the file from the app bundle to the documents directory if it does not exists. This should be done before adding the persistent store to the persistent store coordinator ensure that there is pre-populated data:
*/

let storePath : NSString = self.applicationDocumentsDirectory().stringByAppendingPathComponent("MyDb.sqlite")
        let fileManager : NSFileManager = NSFileManager.defaultManager()
        var fileCopyError:NSError? = NSError()
        if !fileManager.fileExistsAtPath(storePath) {
            let defaultStorePath : NSString! = NSBundle.mainBundle().pathForResource("MyDb", ofType: "sqlite")
            if(defaultStorePath) {
                fileManager.copyItemAtPath(defaultStorePath, toPath: storePath, error: &fileCopyError)
            }
        }

以上是关于java [iOS]复制预先填充的SQLite文件的主要内容,如果未能解决你的问题,请参考以下文章