代码改变世界

Foundation框架系列-NSArray

2018-06-24 02:51  iCoderHong  阅读(161)  评论(0编辑  收藏  举报

NSArray常用API

数组字符串指定字符拼接

// 将数组中的元素以separator拼接返回字符串 比如@[@"a=1", @"b=2"] 以separator=&拼接返回字符串@"a=1&b=2"
- (NSString *)componentsJoinedByString:(NSString *)separator;

遍历数组

[arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        // 遍历数组
        // obj当前遍历索引对应value index为当前遍历索引
        NSLog(@"obj=%@, idx=%lu", obj, (unsigned long)idx);
        
        // 需要停止遍历 stop = YES;
    }];