Use of NSRange *yrange in devowelizer?


#1

i am confused about the purpose of a bit of code,
here it is:

NSRange yrange = [string rangeOfString:@"y" options:NSCaseInsensitiveSearch]; //did it find y? if (yrange.location != NSNotFound) { *stop = YES; }
i am not sure exactly what that does, my output is the same as before i added that.
Thanks


#2

Can you post the whole block please?

Providing it was implemented in the right section of the block it should:

  1. search the string for the letter y (case insensitive)
  2. set the BOOL to stop
  3. stop the current iteration (you’re missing the ‘return’, so you should get one extra line)

If you post the whole block, happy to help out.


#3

As Tiberius mentioned, you’re missing the return in the last line.

Basically it’s just to show that changing the BOOL value at the end of the block assignment from the default (NO), which will iterate through your whole array (oldStrings, in this case), to YES, which stops at its current iteration.

In my output it stops at Sauerkraut because the next word in the oldStrings array is Raygun, containing a y.

Everything else was the same in my code to yours, so I assume if you add the return at the end it will work like mine.


#4

If you leave the return out, you’ll just get one extra line. The fact that he’s seeing all the lines of code makes me think he has the block in the wrong area.