coredata - 移动到应用程序组目标 [英] coredata - move to app group target

查看:110
本文介绍了coredata - 移动到应用程序组目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Today的新用户并使用嵌入式框架。

I am new to the Today extension and using an embedded framework.

我们的应用程序目前使用由sqlite支持的核心数据。如果我想在应用程序和今天的扩展之间共享这个,我应该移动到一个框架,由两者共享?

Our app currently uses core data backed by sqlite. If I want to share this between the app and the today extension, should I move this to a framework to be shared by both?

如何在应用商店中迁移我们当前的版本,以便升级到新的结构?

How can I migrate our current version in the app store to be able to upgrade to a new structure?

推荐答案

您需要确保模型和持久存储文件都可用于应用和扩展程序。

You need to make sure both the model and the persistent store file are available to both the app and the extension.

模型,将其移动到框架是一个好主意,因为它意味着只有一个模型文件的副本。只要应用程序和扩展链接到框架,它将可用于两者。如果你这样做,最好放置在框架中设置Core Data堆栈的代码,因为在这两种情况下都是一样的。

For the model, moving it to a framework is a good idea since it means there's only one copy of the model file. As long as both the app and the extension link to the framework, it'll be available to both. If you do that, it's probably a good idea to put the code that sets up the Core Data stack in the framework too, since it'll be the same in both cases.

你当然可以将模型包含在两个目标中。这将意味着你会有两个副本的文件,这浪费了空间。

You can of course just include the model in both targets. That will mean you'll have two copies of the file, which wastes space. Probably not a lot of space, though.

对于永久存储,您必须设置一个应用程序组并在组目录中使用存储文件。应用组是应用和扩展程序的功能中的设置之一 - 启用它并创建组名称。然后将持久存储文件放在组目录中,您可以使用

For the persistent store, you'll have to set up an app group and use a store file in the group directory. App groups is one of the settings in "capabilities" for the app and extension-- turn it on and create a group name. Then put the persistent store file in the group directory, which you can find using code like

NSURL *groupURL = [[NSFileManager defaultManager]
    containerURLForSecurityApplicationGroupIdentifier:
        @"GROUP NAME HERE"];

[我更详细地介绍了一些在我的博客]。

[I cover some of this in more detail at my blog].

如果您有现有数据,它到新的存储文件。

If you have existing data, you'll have to move it to the new store file. This would look something like


  1. 检查是否存在旧的非群组副本

  2. 如果是这样,请使用该文件设置Core Data堆栈。然后使用 migratePersistentStore:toURL:options:withType:error:将其移动到新位置。

  1. Check if the old non-group copy of the data exists
  2. If it does, set up a Core Data stack using that file. Then use migratePersistentStore:toURL:options:withType:error: to move it to the new location. Then remove the old copy.
  3. If the old version doesn't exist, just set up Core Data with the new copy as usual.

这篇关于coredata - 移动到应用程序组目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆