I was trying to filter my array of objects by one of its properties. tried lot of solutions but it was throwing error after I start typing
//My model class
class Book{
var bookId:Int?
var bookName:String?
//omitted init function
}
// viewController //this is my textfield delegate method
let myArray:[Book] = [Book(bookId:23,bookName:"book1"),Book(bookId:53,bookName:"book2"),Book(bookId:43,bookName:"book3"),]
func textField(_ textField: UITextField, shouldChangeCharactersIn
range: NSRange, replacementString string: String) -> Bool
{
lastCharactar = string
textFieldText = myTextField.text! + lastCharactar
let predicate = NSPredicate(format: "ANY SELF.bookName BEGINSWITH %@", textFieldText)
let arr = ( myArray as NSArray).filtered(using: predicate)
return true
}
I am getting the following error
"this class is not key value coding-compliant for the key bookName."