Search
Rich's Mad Rants
Powered by Squarespace

Creating iOS 5 Apps Discussion > Page 387 - Errata in [size] predicate code examples

The book gives these examples for [size] predicates...

// Determines if the target has at least 3 children.
[NSPredicate predicateWithFormat:@"children[size] < 3"];
...
// Determines if the target has at least 3 adult children.
[NSPredicate predicateWithFormat:@"(children[size] < 3) AND (NONE children.age < %@)", [NSNumber numberWithInt:18]];

I didn't test these, but wouldn't the first return targets with less than 3 children, and the second with less than 3 children aged 18 or older? So the code examples should be...

// Determines if the target has at least 3 children.
[NSPredicate predicateWithFormat:@"children[size] > 2"];
...
// Determines if the target has at least 3 adult children.
[NSPredicate predicateWithFormat:@"(children[size] > 2) AND (NONE children.age < %@)", [NSNumber numberWithInt:18]];

January 3, 2012 | Unregistered CommenterScott

Oops. Yes. Definitely.

January 4, 2012 | Registered CommenterRichard Warren