微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何修复错误:@FetchRequest 中的“属性初始值设定项运行于”自我“可用”之前

如何解决如何修复错误:@FetchRequest 中的“属性初始值设定项运行于”自我“可用”之前

我有以下结构,在@FetchRequest 中,我在谓词 var 'nomAcuariL' 中得到一个错误,我不知道如何解决这个错误,我该如何初始化该属性

错误

enter image description here

 import SwiftUI
    
    struct Llist: View {
        
        var nomAcuariL : String
        var parametres : Parametres
        
        @Environment(\.managedobjectContext) var moc
    
        
        @FetchRequest(entity: Parametres.entity(),sortDescriptors: [NSSortDescriptor(keyPath: \Parametres.nomParametres,ascending: true)],predicate: nspredicate(format: "nomParametres = %@",nomAcuariL)) var contactos: FetchedResults<Parametres>
    
        
        var body: some View {
            
            List{
                ForEach(contactos,id:\.self){ contact in
                    Text("\(contact.nomParametres ?? "")")
                }
            }
        }
    }

解决方法

您不能在 FetchRequest 中使用实例成员 nomAcuariL,因为它尚未初始化。换句话说,当您尝试初始化 FetchRequest 时它不存在。您需要将该值传递给某个已经存在的对象的 fetch 请求。尝试使用您可以在其中实例化包含数据的类或结构,或者简单地使用文字字符串。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。