2
コアデータを検索しようとしていますが、デフォルトでタイトル属性を検索していますが、結果を並べ替える必要があります。date
コアデータの属性を日付と文字の両方でソート
私のコードはtitle
属性を検索しますが、predicates
を2つ作成して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;
}
私はちょうど 'date'でソートしています –