【发布时间】:2021-09-27 10:20:46
【问题描述】:
import SwiftUI
import Foundation
import CoreData
struct FilteredList: View {
var fetchRequest: FetchRequest<FeedList>
var value: FetchedResults<FeedList> {
fetchRequest.wrappedValue
}
var total: Double = 0.0
var body: some View {
ForEach(value, id: \.self) {value in
Text("Feed quantity is: \(value.feedquant.reduce(0) { $0 + $1.value}) ")
}
}
init(filter: String) {
fetchRequest = FetchRequest<FeedList>(entity:
FeedList.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \FeedList.compdate, ascending: false)],
predicate: NSPredicate(format: "compdate == %@", filter))
}
}//: View
我的 CoreData 中有两个属性。 Compdate 存储为日期字符串,feedquant 存储为双精度值。我能够过滤以通过 init 获取今天值的获取请求,但我无法以不会导致错误的方式对属性求和。像上面一样,任何在视图中求和的尝试都会导致
类型“()”不能符合“AccessibilityRotorContent”。 -或者- 类型 '()' 不符合 'View'
到目前为止,对于我在必须按另一个属性进行过滤时对核心数据中的属性求和的情况,没有任何 stackoverflow 解决方案有效。
【问题讨论】:
标签: core-data swiftui nsfetchrequest