操作特定CoreData实体时XCode构建极慢但可成功完成
CoreData实体操作导致Xcode构建缓慢问题
我开发的一款使用CoreData/iCloud NSPersistentCloudContainer的应用,在新增Reminder实体后,只要操作该实体,Xcode的构建时间就变得极慢。不过构建最终可成功完成,且应用在模拟器中运行速度正常。若代码存在错误(如缺失括号),还会出现无有效描述的报错:
The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
我已定位到特定代码行,注释掉这些操作Reminder实体的代码后,应用即可正常速度构建。我怀疑是访问Reminder实体的方式有误,此前模型中的其他实体均未出现该问题。
问题代码示例
ForEach(dataModel.activeReminders){ reminder in if(reminder.note != nil && reminder.time! < Date()){ //注释此行后构建恢复正常 VStack{ NoteView(namespace: namespace, note: reminder.note!) .frame(maxWidth: .infinity) NoteViewFooter(namespace: namespace, note: reminder.note!) HStack{ Button{ withAnimation(.easeIn){ reminder.isCompleted = true //注释此行后构建恢复正常 } dataModel.saveMoc() dataModel.getReminders() }label:{ HStack{ Image(systemName: "checkmark.circle") .foregroundColor(Color.white) Text("Mark as Complete") } .frame(maxWidth: .infinity, alignment: .center) .font(.footnote) .fontWeight(.semibold) .foregroundColor(Color.white) .padding(.vertical, 6) .background(Color("ReminderGreen")) .cornerRadius(20) } Button{ model.selectedNote = reminder.note withAnimation(.easeIn){ showEditAlert = true } }label:{ Text("Edit alert") .frame(maxWidth: .infinity, alignment: .center) .font(.footnote) .padding(.vertical, 6) .foregroundColor(Color("AccentColor")) .background(Color("SelectedColor")) .cornerRadius(20) } } .frame(maxWidth: .infinity) .padding(.horizontal, 24) } .frame(maxWidth: .infinity, alignment: .leading) .padding(.bottom, 16) } //注释此行后构建恢复正常
相关截图说明
- CoreData模型截图:展示Reminder实体的属性配置
- CoreData调用截图:展示获取Reminders数据的代码逻辑
- 代码界面截图:展示上述问题代码的实际编辑界面
内容的提问来源于stack exchange,提问作者Hal219
相关产品推荐
相关产品推荐

