MagicalRecord(CoreData)+今天扩展(iOS8)...他们玩吗? [英] MagicalRecord (CoreData) + Today Extension (iOS8)... Will They Play?
问题描述
希望你能帮忙。我要为我的应用添加今天的支持,该应用使用MagicalRecord https://github.com/magicalpanda/MagicalRecord管理我的所有CoreData资料。
Hoping you can help. I'm adding Today support to my app, which uses MagicalRecord https://github.com/magicalpanda/MagicalRecord to managing all my CoreData stuff.
我撕掉了我的头发,试图了解如何将我的数据表达到今天的扩展。
I'm tearing my hair out trying to understand how to surface my data into the Today extension.
我已启用此处列出的应用组 http://blog.sam-oakley.co.uk/post/92323630293/sharing-core-data-between-app-and-extension-in-ios -8 然而,我正在阅读的所有文档和StackOverflow帖子涉及直接使用CoreData。 MagicalRecord为你做了很多艰苦的工作,这就是为什么我使用它,因为我是完全新的在这个项目的开始。例如:
I have enabled app groups as outlined here http://blog.sam-oakley.co.uk/post/92323630293/sharing-core-data-between-app-and-extension-in-ios-8 however all the documentation and StackOverflow posts I'm reading relate to using CoreData directly. MagicalRecord does a lot of the hard work for you, which is why I used it as I was totally new to it all at the beginning of this project. So things like:
在初始化你的Core Data栈的时候,你会在
中添加一个存储到persistStoreCoordinator像这样:
Where you initialise your Core Data stack, you’ll be adding a store to your persistentStoreCoordinator a little something like this:
[persistentStoreCoordinator
addPersistentStoreWithType:NSSQLiteStoreType configuration:nil
URL:storeURL options:options error:&error]
这只是一个问题,将storeURL
(通常是NSDocumentDirectory中的某个位置)的先前值更改为共享应用程序组文件夹中
中包含的位置。您可以使用
It’s simply a matter of changing your previous value for storeURL (usually somewhere in NSDocumentDirectory) to a location contained in your shared App Group folder. You do this using
containerURLForSecurityApplicationGroupIdentifier: NSURL *directory =
[[NSFileManager defaultManager]
containerURLForSecurityApplicationGroupIdentifier:@"group.YourGroupName"];
NSURL *storeURL = [directory
URLByAppendingPathComponent:@"YourAppName.sqlite"];
...我不明白如何/在哪里实施。
... I'm not understanding how / where to implement.
我想象我只需要在我的扩展中设置MagicalRecord堆栈,就像在我的appDelegate中一样,但是它失败了。
I'd imagined I'd just have to set up the MagicalRecord stack in my extension as I do in my appDelegate, but of course it's failing.
真的希望有人处于类似的情况,并且能够阐明如何继续前进。
Really hoping someone might be in a similar situation and be able to shed some light on how to move forward with this one.
您需要的任何代码
提前感谢
推荐答案
更改
[MagicalRecord setupCoreDataStackWithStoreNamed:@"Database"];
到
- (void)setupCoreDataStack
{
if ([NSPersistentStoreCoordinator MR_defaultStoreCoordinator] != nil)
{
return;
}
NSManagedObjectModel *model = [NSManagedObjectModel MR_defaultManagedObjectModel];
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
NSURL *storeURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.yourgroup"];
storeURL = [storeURL URLByAppendingPathComponent:@"Database.sqlite"];
[psc MR_addSqliteStoreNamed:storeURL withOptions:nil];
[NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:psc];
[NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:psc];
}
这篇关于MagicalRecord(CoreData)+今天扩展(iOS8)...他们玩吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!