Xcode 12.5 Ios 14 Cocoa DataAbstract - How to format the NSPredicate for a blank field

What should we use in the NSPredicate for searching a field which is blank but not necessarily nil. We can find records when we are searching for an exact value but not when the field value is a blank string.

Our code is below for the function where we are searching timesheet entries. The field that is giving us the problem is the Out_Time field. We are needing to return the list of entries where the Out_Time is still blank.

Normally in a sql statement we would have either used a trim() or a length() function on that field.

Thanks.

If by blank you mean empty, you can do “x = nil || x = ''”. if you need to account for whitespace too, then I don;t believe NSPredicate can cover that. You cold add a calculated field, xTrimmed, that returns the trimmed value, and use that in the predicate, maybe…

Thanks Mark. I used your suggested code with the Or and we think that will work. Pulled the right records anyway. Should know by end of day if this works in all scenarios since we are testing this morning with several hundred actual entries pulled from a live time clock system. This is trying to pull entries for a person that has already clocked in and we need to update the clock out time.

1 Like