課程
/移動(dòng)開發(fā)
/iOS
/iOS基礎(chǔ)入門之Foundation框架初體驗(yàn)
第三種是什么方法?怎么沒有講!
2015-07-31
源自:iOS基礎(chǔ)入門之Foundation框架初體驗(yàn) 3-2
正在回答
//迭代器
? ? ? ? NSEnumerator *enumerator = [array1 objectEnumerator];
? ? ? ? id obj = nil;
? ? ? ? while(obj = [enumerator nextObject]){
? ? ? ? ? ? NSLog(@"obj=%@",obj);
? ? ? ? }
?,使用block的方式進(jìn)行遍歷
? ? ? ? obj 是每個(gè)元素
? ? ? ? ?idx 元素的下標(biāo)
? ? ? ? ?stop ? ? ? BOOL類型的一個(gè)指針變量,用于控制循環(huán)是否要停止
? ? ? ? ? ? ? ? ? ?NSArray *arr = @[@"one",@"two",@"three"];
? ? ? ? ? ? ? [arr enumerateObjectsUsingBlock:^(id? _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
? ? ? ? ? ? if (idx==2) {
? ? ? ? ? ? ? ? //*stop賦值YES的時(shí)候,表示需要停止循環(huán)
? ? ? ? ? ? ? ? // stop 默認(rèn)值是NO
? ? ? ? ? ? ? ? *stop = YES;
? ? ? ? ? ? }
? ? ? ? ? ? NSLog(@"arr[%lu] = %@",idx,obj); ? ??
? ? ? ? }]; ? ? ?//中括號(hào)在這里
? ? }
? ? return 0;
}
舉報(bào)
學(xué)會(huì)Foundation框架,能滿足你所需要的大部分東西
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2019-07-17
//迭代器
? ? ? ? NSEnumerator *enumerator = [array1 objectEnumerator];
? ? ? ? id obj = nil;
? ? ? ? while(obj = [enumerator nextObject]){
? ? ? ? ? ? NSLog(@"obj=%@",obj);
? ? ? ? }
2015-12-16
?,使用block的方式進(jìn)行遍歷
? ? ? ? obj 是每個(gè)元素
? ? ? ? ?idx 元素的下標(biāo)
? ? ? ? ?stop ? ? ? BOOL類型的一個(gè)指針變量,用于控制循環(huán)是否要停止
? ? ? ? ? ? ? ? ? ?NSArray *arr = @[@"one",@"two",@"three"];
? ? ? ? ? ? ? [arr enumerateObjectsUsingBlock:^(id? _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
? ? ? ? ? ? if (idx==2) {
? ? ? ? ? ? ? ? //*stop賦值YES的時(shí)候,表示需要停止循環(huán)
? ? ? ? ? ? ? ? // stop 默認(rèn)值是NO
? ? ? ? ? ? ? ? *stop = YES;
? ? ? ? ? ? }
? ? ? ? ? ? NSLog(@"arr[%lu] = %@",idx,obj); ? ??
? ? ? ? }]; ? ? ?//中括號(hào)在這里
? ? }
? ? return 0;
}