2

我有一个带有 Today 扩展的应用程序。

我在框架中有 CoreData 相关代码和预加载的 .sqlite 数据库。

我需要从应用程序和小部件中获取该 .sqlite 资源的 URL,以将其保存到应用程序组容器。

像这样的东西:

let url = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.com.ysoftware.Anecdotes")!.URLByAppendingPathComponent("db.sqlite")
    if (!NSFileManager.defaultManager().fileExistsAtPath(url.path!)) {
        let preloadedStorePath = NSBundle.bundleWithIdentifier("company.Framework").pathForResource("db", ofType:"sqlite") //this line 
        NSFileManager.defaultManager().copyItemAtPath(defaultStorePath!, toPath:url.path!, error: nil)
    }

我可以这样做吗?怎么做?

4

0 回答 0