环境中的上下文未连接到持久性存储协调器

问题描述

因此,我尝试使用以下代码对ForEach列表中的值求和:

@Environment(\.managedobjectContext) var managedobjectContext
@FetchRequest(entity: Transaction.entity(),sortDescriptors: [NSSortDescriptor(keyPath: \Transaction.value,ascending: false)]) var fetchRequest: FetchedResults<Transaction>

var sum: Double {
    fetchRequest.reduce(0) { $0 + $1.value } //ERROR! 
    } 

每次我跑步时,都会出现错误

[SwiftUI]环境中的上下文未连接到持久性 商店协调员:

使用PO:

(lldb) po fetchRequest
error: warning: Couldn't get required object pointer (substituting NULL): Couldn't load 'self' because its value Couldn't be evaluated

这是其余的代码

var body: some View {
    NavigationView {
            Form {
                ...
                            Text("\(sum)")
                        }
                }
                ...

能帮我找到错误吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)