gpt4 book ai didi

swift - 将变量传递给 FetchRequestController - Swift

转载 作者:行者123 更新时间:2023-11-30 11:39:17 28 4
gpt4 key购买 nike

我已经定义了一个变量,我想在 FetchRequestController 内的谓词中使用它。

    var subuserID : String = "0"
lazy var fecthResultsControllerDocList : NSFetchedResultsController = { () -> NSFetchedResultsController<DocumentTypeList> in



let fecthRequest : NSFetchRequest<DocumentTypeList> = DocumentTypeList.fetchRequest()

let predicate = NSPredicate(format: "dltPresent == %@", NSNumber(value: true))



let loggedUser = Auth.auth().currentUser

let userId = loggedUser?.uid

let predicateUser = NSPredicate(format: "dltUserID == %@", userId!)

let predicateSubuser = NSPredicate.init(format: "dltSubuserID", self.subuserID)



let compoundPredicate = NSCompoundPredicate.init(type: .and, subpredicates: [predicateUser, predicate, predicateSubuser])

fecthRequest.predicate = compoundPredicate

let sortDescript = NSSortDescriptor(key: "dltID", ascending: true)

fecthRequest.sortDescriptors = [sortDescript]

let controller = NSFetchedResultsController(fetchRequest: fecthRequest, managedObjectContext: PersistenceService.context, sectionNameKeyPath: nil, cacheName: nil)



controller.delegate = self

return controller

}()

当我运行此代码时,它因以下原因而崩溃:

   2018-03-22 13:11:38.479 AppName[5640:344901] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "dltSubuserID"'

基本上我想使用前一个 ViewController 传递的变量来预测所有结果。任何帮助,将不胜感激。

最佳答案

缺少运算符和占位符(如前一行)

let predicateSubuser = NSPredicate(format: "dltSubuserID == %@", self.subuserID)
<小时/>

注意:

dltPresent 谓词行可以简化为

let predicate = NSPredicate(format: "dltPresent == TRUE")

关于swift - 将变量传递给 FetchRequestController - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49423439/

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