Wildcard Side

I’ve been having some more fun with NSPredicates.  They have a really annoying “feature” in 10.4 that gave me a bit of a headache and will hopefull be changed before long.  According to the Predicate Programming Guide:

In Mac OS X v10.4, wildcard characters do not match newline characters.

I took that to mean that the wildcard portion of the match could not could not contain a newline. Something like “a\n b” would not match for “a*b”. What it really means is that if the string has a newline character in it, a match will not occur.  So if the string is something like “this is an example\n string”, a LIKE predicate matching on “*exa*” will not match.  Any newline characters need to be stripped out first.

2 Responses to “Wildcard Side”

  1. Peter Hosey Says:

    The wildcard (*) covers the newline in both of the examples you gave.

  2. brad Says:

    I didn’t actually test against those two cases. They were made up when writing the post. I just used \n as an example. It might have been one of the other newline characters that was at fault. I’m striping using NSCharacterSet’s whitespaceAndNewlineCharacterSet with the whitespace characters removed.

    I ran up against it when testing against real world data. It was happening when I was setting a predicate on an NSArrayController or in a CoreData fetch. The results weren’t what I expected and I noticed that the only item being returned had no line breaks. I added in the newline stripping and the expected results came back. No other changes were made.

Leave a Reply