views:

153

answers:

2
for(LevelMeter *thisMeter in _subLevelMeters){
{
xxxxx
}

I am new to iphone development.I am doing research on voice recording in iphone .I have downloaded the "speak here " sample program from Apple.I came across the above code in the sample program.I cant understand the for loop.LevelMeter is separate class._subLevelMeters is a NSArray.They have used "in" inside for loop.So please anyone tell the function of the above for loop.Please help me out.Thanks.

+1  A: 

_subLevelMeters is an NSArray that contains a number of LevelMeter objects.

The syntax being used here is Objective-C 2.0's fast enumeration.

Basically, it's like saying "for each LevelMeter object in the _subLevelMeters array, do this code". Or to put it a in more colloquial fashion: "Do this stuff for each LevelMeter in the array".

Hope that helps.

Jasarien
+3  A: 

This is just a standard for..in loop that is found in many languages. With each iteration of the loop the variable thisMeter contains the next object in the array. An example should make this clear:

NSArray *array = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];

for(id *string in array)
{
  NSLog(string);
}

// The above code will output the following:
// 1
// 2
// 3
pheelicks