gpt4 book ai didi

ios - 无法推断复杂的闭包返回类型 SwiftUI ForEach

转载 作者:行者123 更新时间:2023-11-29 05:11:23 24 4
gpt4 key购买 nike

我试图显示一个过滤后的List,其中仅包含与self.day[index]完全匹配的subjects。但是,当我尝试为此使用 if 子句时,收到错误 Unable to infer Complexclosure return type;添加显式类型以消除歧义。有人可以找到任何其他方法来通过 subject.day 过滤 subject 使其等于 self.days[index] 吗?这是我的代码,谢谢:

import SwiftUI
import CoreData

struct ProfileView: View {
@Environment(\.managedObjectContext) var moc: NSManagedObjectContext
@FetchRequest(
entity: Subject.entity(),
sortDescriptors:[
//NSSortDescriptor(keyPath: \Subject.day, ascending: true),
NSSortDescriptor(keyPath: \Subject.start, ascending: true)
]
) var subjects: FetchedResults<Subject>

@State private var showAddScreen = false
@State private var name: String = ""
@State private var surname: String = ""
let days = ["Pondelok", "Utorok", "Streda", "Štvrtok", "Piatok"]

var body: some View {
Form {
ForEach(0 ..< days.count) { index in
Section {
Text(self.days[index])
List {
ForEach(self.subjects, id: \.self) { subject in //here the { shows an error, If I remove the if clause, it works, but obviously I don't have subjects filltered, which is what I need
if subject.day == self.days[index] {
SubjectCell(name: "\(subject.name!)",
place: "\(subject.place!)",
start: self.formatTime(date: subject.start ?? Date()),
end: self.formatTime(date: subject.end ?? Date()),
type: subject.type,
occurance: subject.occurance)
}
}
.onDelete(perform: self.deleteSubject)

最佳答案

将整个 if {..} 包装到 Group {..} 解决了问题

关于ios - 无法推断复杂的闭包返回类型 SwiftUI ForEach,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59645479/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com