I'm attempting to filter an array of arrays which contains a core data entity of type Bird. The entities have been split into arrays of arrays based on a UITableView with sections and rows.
To search I have the following method based on this question NSPredicate on array of arrays:
func filterContentForSearchText(searchText: String) {
let resultPredicate = NSPredicate(format: "SELF[0].common_name contains[cd] %@", searchText)
self.filteredBirds = self.birds.filteredArrayUsingPredicate(resultPredicate!)
}
This however results in the error
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
which probably makes sense because the array has 27 (A-Z, #) elements of which some have no entities
So, how can I adjust the NSPredicate query to take into consideration some arrays maybe empty?