基于@FetchedRequest的SwiftUI列表并过滤计算的属性崩溃

时间:2019-12-10 09:19:09

标签: list swiftui fetchrequest

我有这样的代码,它具有@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])) {

0 个答案:

没有答案