【发布时间】:2016-07-21 18:56:52
【问题描述】:
我正在尝试搜索我的核心数据,默认情况下它搜索标题属性,但我还需要按 date 对结果进行排序。
我的代码搜索 title 属性,但我怎样才能创建两个 predicates 并将它们与 context 连接起来?
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
let currentText = textField.text ?? ""
let prospectiveText = (currentText as NSString).stringByReplacingCharactersInRange(range, withString: string)
//Load data from Core Data
let appDel : AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
context = appDel.managedObjectContext
do {
request = NSFetchRequest(entityName: "Event")
let sort:NSSortDescriptor = NSSortDescriptor(key:"title", ascending: true)
request.sortDescriptors = [sort]
let searchPredicate = NSPredicate(format: "title CONTAINS[c] %@", prospectiveText)
request.predicate = searchPredicate
results = try context.executeFetchRequest(request)
animateTableCell()
} catch {
print("ERROR")
}
return true;
}
【问题讨论】:
标签: ios iphone swift xcode core-data