Crooked Spin

Programming

March 1, 2007

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.

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

    Comment by Peter Hosey — March 4, 2007 @ 5:27 am
  2. 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.

    Comment by brad — March 4, 2007 @ 9:19 am

Leave a comment

RSS feed for comments on this post. TrackBack URL

You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>