Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 核心数据NSPredicate不工作_Ios_Swift_Core Data - Fatal编程技术网

Ios 核心数据NSPredicate不工作

Ios 核心数据NSPredicate不工作,ios,swift,core-data,Ios,Swift,Core Data,请帮助我没有任何具体错误,运行时停止 func fachDataById(entityName: String, colummName: String, value: Int) -> Bool { let appDeleget = UIApplication.sharedApplication().delegate as! AppDelegate let manegeContext = appDeleget.managedObjectContext let fetc

请帮助我没有任何具体错误,运行时停止

func fachDataById(entityName: String, colummName: String, value: Int) -> Bool {
    let appDeleget = UIApplication.sharedApplication().delegate as! AppDelegate
    let manegeContext = appDeleget.managedObjectContext
    let fetchRequist = NSFetchRequest(entityName: entityName)
    print("ok fetchRequist")
    fetchRequist.predicate = NSPredicate(format: "%K == %@", colummName, value)

    do{
        let results = try manegeContext.executeFetchRequest(fetchRequist)
        print(results)
        return true
    }
    catch{
        print("Error")
        return false
    }
}


问题是value:Int的%@格式,将其转换为NSObject或任意对象,如下所示:

NSPredicate(format: "%K == %@", colummName, value as NSObject)

尝试插入一些断点并检查您的字段,看看它们是否是您期望的值。ColumnName和value是否是您在coredata表中使用的期望值?您调试了吗?你检查变量值了吗?它们有效吗?不能将%@用于Int值。看见