我有这样的代码,它具有@FetchRequest加载联系人,然后我根据@State变量进行了过滤的计算属性
@FetchRequest var fetchRequest: FetchedResults<Contact>
private var contacts : Array<Contact> {
Array(fetchRequest).filter { contact in
if self.sectionSelection == 1 {
return contact.type == "person"
} else if self.sectionSelection == 2 {
return contact.type == "company"
} else {
return true
}
}
}
@State private var sectionSelection : Int = 0
但是列表崩溃,索引超出范围错误!
List {
ForEach(0..<contacts.count) { i in
ZStack {
NavigationLink(destination: ContactDetails(contact: contacts[i])) {