问题描述
因此,我尝试使用以下代码对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 (将#修改为@)