【发布时间】:2025-12-18 11:00:01
【问题描述】:
我是 Grand Central Dispatch (GCD) 和 Core Data 的初学者,我需要您的帮助才能将 Core Data 与 CGD 一起使用,以便在我向 Core Data 添加 40.000 条记录时 UI 不会被锁定。
我知道CD不是线程安全的,所以我必须使用另一个上下文,然后保存数据并合并上下文,据我从一些文章中了解到。
我还不能做的就是把碎片拼在一起。
所以,在我的代码中,我需要你的帮助来解决这个问题。
我有:
/*some other code*/
for (NSDictionary *memberData in arrayWithResult) {
//get the Activities for this member
NSArray *arrayWithMemberActivities = [activitiesDict objectForKey:[memberData objectForKey:@"MemberID"]];
//create the Member, with the NSSet of Activities
[Members createMemberWithDataFromServer:memberData
andActivitiesArray:arrayWithMemberActivities
andStaffArray:nil
andContactsArray:nil
inManagedObjectContext:self.managedObjectContext];
}
如何将其转换为在后台运行,然后在保存完成后保存数据并更新 UI,而不会在保存 40.000 个对象时阻塞 UI?
【问题讨论】:
标签: iphone ios multithreading core-data grand-central-dispatch