for in ループにスコープ外の変数を指定して、最後の項目を取得しようとしてもうまくいかない。ループを終えたときには nil になっている。
NSArray *ary=[NSArray arrayWithObjects:@"a", @"b", @"c", nil];
id item=@"test start";
id other=nil;
for (NSInteger i = 0; i<[ary count]; i++) {
item=[ary objectAtIndex:i];
}
NSLog(@"for = %@", item); // for = c
item=@"for end";
for (item in ary) {
item=item;
other=item;
}
NSLog(@"for in = %@", item); // for in = (null)
NSLog(@"other = %@", other); // other = c