[英]Core Data Fetch Request Error
我试图基于属性名称获取记录。
我也尝试搜索类似的问题,但是我找不到解决方案,所以我发布了问题...
但在获取时出现异常:
[error] error: exception handling request: <NSSQLFetchRequestContext: 0x1c019a270> , keypath audio_1.m4a not found in entity <NSSQLEntity answer id=8> with userInfo of (null)
CoreData: error: exception handling request: <NSSQLFetchRequestContext: 0x1c019a270> , keypath audio_1.m4a not found in entity <NSSQLEntity answer id=8> with userInfo of (null)
2017-09-28 19:03:36.725060+0530 app[9684:891158] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath audio_1.m4a not found in entity <NSSQLEntity answer id=8>'
我的代码:
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: Entity)
if let predic = predicate_str{
let predicate = NSPredicate(format: predic)
fetchRequest.predicate=predicate
}
do {
let arr = try appsession.managedObjectContext.fetch(fetchRequest) //CRASHED
// success ...
} catch let error as NSError {
// failure
print("Fetch failed: \(error.localizedDescription)")
return(nil,error)
}
谢谢,
您在错误地构建谓词字符串。 要匹配的值必须在引号内,因此您需要像这样构建它:
let predicate = NSPredicate(format: "%K LIKE[c] %@", "imagePath", "audio1.m4a")
解析为以下谓词字符串:
imagePath LIKE[c] "audio1.m4a"
请注意您要匹配的值周围的引号,以及属性名称周围没有引号。 您当前的谓词尝试查找其imagePath
属性与其audio1.m4a
属性具有相同值的记录,该记录不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.