gpt4 book ai didi

ios - 核心数据管理对象上下文保存

转载 作者:行者123 更新时间:2023-11-29 03:12:27 24 4
gpt4 key购买 nike

我设置了两个 NSManagedObjectContext,一个在主线程上,一个在后台线程上。我目前正在尝试实现 NSFetchedResultsController,但主线程的保存通知似乎不包含像后台线程那样的更改。

关于如何解决这个问题有什么想法吗?这是通知的样子(首先记录后台保存,然后是主保存)。

2014-02-28 15:14:24.210 Lift[62931:70b] Notification found with:
name: NSManagingContextDidSaveChangesNotification
object: <NSManagedObjectContext: 0x109280700>
userInfo: {
inserted = "{(\n)}";
updated = "{(\n <Message: 0x109622cc0> (entity: Message; id: 0xd000000000a40006 <x-coredata://B1800ECF-053B-417C-81C0-CD304EF83F19/Message/p41> ; data: {\n \"awaiting_reply\" = 0;\n \"body_excerpt\" = \"\\n\\nOn Friday, February 28, 2014 at 12:17 AM, Cody Robertson wrote:\\n\\n> \\n> \\n> On Friday, February 28, 2014 at 12:16 AM, Cody Robertson wrote:\\n> \\n> > \\n> > \\n> > On Friday, February 28, 2014 at 12:12 AM, Co\";\n cc = \"<relationship fault: 0x109302a10 'cc'>\";\n date = \"2014-02-28 05:19:19 +0000\";\n \"expiration_date\" = nil;\n \"expiration_length\" = 259200;\n folder = \"lift:in\";\n from = \"0xd0000000000c0008 <x-coredata://B1800ECF-053B-417C-81C0-CD304EF83F19/UserInfo/p3>\";\n id = 53101bd032ef5519958b4ecb;\n mailbox = \"0xd000000000040000 <x-coredata://B1800ECF-053B-417C-81C0-CD304EF83F19/Mailbox/p1>\";\n read = 0;\n subject = \"Re: A New Email!\";\n thread = \"0xd00000000060000a <x-coredata://B1800ECF-053B-417C-81C0-CD304EF83F19/Thread/p24>\";\n to = \"<relationship fault: 0x1093002a0 'to'>\";\n}),\n <Message: 0x10975bfd0> (entity: Message; id: 0xd000000000b80006 <x-coredata://B1800ECF-053B-417C-81C0-CD304EF83F19/Message/p46> ; data: {\n \"awaiting_reply\" = 0;\n \"body_excerpt\" = \"\\n\";\n cc = \"<relationship fault: 0x109760580 'cc'>\";\n date = \"2014-02-28 18:33:25 +0000\";\n \"expiration_date\" = nil;\n \"expiration_length\" = 259200;\n folder = \"lift:in\";\n from = \"0xd0000000000c0008 <x-coredata://B1800ECF-053B-417C-81C0-CD304EF83F19/UserInfo/p3>\";\n id = 5310d5eb32ef5519958b4fa7;\n mailbox = \"0xd000000000040000 <x-coredata://B1800ECF-053B-417C-81C0-CD304EF83F19/Mailbox/p1>\";\n read = 0;\n subject = \"New Message\";\n thread = \"0xd0000000007c000a <x-coredata://B1800ECF-053B-417C-81C0-CD304EF83F19/Thread/p31>\";\n to = \"<relationship fault: 0x10975e910 'to'>\";\n}),\n )}";
}
2014-02-28 15:14:24.228 Lift[62931:70b] Notification found with:
name: NSManagingContextDidSaveChangesNotification
object: <NSManagedObjectContext: 0x10927f670>
userInfo: {
inserted = "{(\n)}";
updated = "{(\n)}";
}

这就是我从后台保存上下文的方式:

- (void)saveFromBackgroundThread:(void(^)(void))completionBlock
{
NSError *error;
if (![_backgroundManagedObjectContext save:&error])
{
NSLog(@"[BACKGROUND_THREAD] - %@", [error localizedDescription]);
}

dispatch_async(dispatch_get_main_queue(), ^{
NSError *error;
if (![_mainManagedObjectContext save:&error])
{
NSLog(@"[MAIN_THREAD] - %@", [error localizedDescription]);
}
else {
if (completionBlock != nil)
{
completionBlock();
}
}
});
}

最佳答案

我应该在 NSManagedObjectContext 类引用文档中找到您的解决方案,特别是阅读“并发”段落。

关于ios - 核心数据管理对象上下文保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22105055/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com