【问题标题】:filtering objects from nsmutablearray with a nsarray of string values使用 nsarray 字符串值从 nsmutablearray 过滤对象
【发布时间】:2013-06-09 17:19:25
【问题描述】:

我有一个名为“scoreBoard”的 NSMutableArray,它有数百个具有属性 name、score、id 的对象

我还有一个名为“friends”的 NSArray,其中包含一个字符串列表

我想用 NSArray "friends" 扫描 "scoreBoard" 中的所有对象 "id",并只保留属性值 id 与 "friends" 列表匹配的对象

谁能给我一些指示?

【问题讨论】:

    标签: xcode properties filter nsmutablearray nsarray


    【解决方案1】:

    类似这样的:

        NSIndexSet *toRemove = [scoreBoard indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
             return [friends containsObject:obj.name];
        }];
        [scoreBoard removeObjectsAtIndexdes:toRemove];
    

    请注意,这并不是最佳速度。您可能还想查看[NSMutableArray filterUsingPredicate:],尽管NSPredicate 不是我的偏好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-18
      • 1970-01-01
      • 2012-05-17
      • 2019-04-04
      相关资源
      最近更新 更多