( i just bought the book last week and i've noticed is the 1-st Printing dec 2011 )
I came across this rather nasty issue for which i have to admit i smashed my head against the wall ( presuming i am making mistakes somewhere and trying to figure it out ... ) and would like to try give an errata on this ...
I am referring here to page 363 to the piece of code mentioned in the book as follows :
-(NSMutableArray *) lookupAll: (NSString *) theName
NSMutableArray * matches = [NSMutableArray array];
NSUInteger result =[book indexOfObjectPassingTest:
^(id obj, NSUInteger idx, BOOL * stop)
if ( [[obj name] caseInsensitiveCompare:theName] == NSOrderedSame ) /* here is another small errata:
in the book it reads =- NSOrderedSame but that takes anyone 1 sec to figure out it's a mistake, on contrary for what
i am about to present here*/
// see if we found any matches
if ( [matches count] )
When reading through the book, the above is an example of how you can build an array that will hold all the indexes for which you can find matching names when searching inside the array of the AddressCards.
Now i can tell you ( i also found now when writing here that someone else found this similar issue in here http://classroomm.com/objective-c/index.php?topic=5949.0
) that this is not working
I just want to try to conclude that indeed indexOfObjectPassingTest method will always
stop to 1-st index the block condition will occur.
However i kept smashed my head against the wall and thought since is written in the book and not on errata it must working, is just me not geting it right yet and falling to understand ... so i thought i found the problem by looking again at this code and see how the block is trying to modify a variable defined outside of the block without the ( double underscore )_ _ block, but then i asked myself why isn't throwing a compilation error anyways as i already learned in previous chapter about blocks ( on how they can modify a variable defiend outside ) ? What do i still miss more regarding this matter ?!
so 2 things please :
1) if i am right, this the 1-st important ( of course from my point of view ! ) errata that could saved me 1 day
2) what do i miss please on the NSMutableArray matches variable defined outside of the block that is trying to be modified inside the block ( [matches addObject: obj] ) - why i can not get a compilation error as suspected because of the lack of __block on variable definition ?