I’m creating an NSPredicate with a date range filter, and using NSArray’s filteredArrayUsingPredicate to return the filtered array.
The predicate runs ok, but it fails on filtering with an ‘unrecognized selector sent to instance’ error.
Here’s the code:
set theYear to "1985"
set df to current application's NSDateFormatter's new()
(df's setDateFormat:"yyyy-MM-dd")
set yearStartString to theYear & "-01-01"
set yearEndString to theYear & "-12-31"
set yearStart to (df's dateFromString:yearStartString) as date
set yearEnd to (df's dateFromString:yearEndString) as date
-- init predicate
set theDateRangePredicate to current application's NSPredicate's predicateWithFormat_("docDate > %@ AND docDate < %@", yearStart, yearEnd)
-- Filter the array using the predicate
set filteredArray to (current application's NSArray's arrayWithArray:docData)'s filteredArrayUsingPredicate:theDateRangePredicate
‘docData’ is a list of dictionaries with ‘docDate’ being a date element in the dict.
Here I’ve used an Applescript date for predicate parameters. But, I’ve also tried explicitly converting to NSDate. Both methods failed.
