English 中文(简体)
可可——删除/去除物品,同时配上国家安全局 Array
原标题:Cocoa - Delete/remove items while parsing a NSMutableArray

我愿用<代码>NSMutableArray,如果我发现一些物体符合某些条件,我就希望从阵列中删除这些物体。

如果没有两个(或更多)阵列,我怎么做?

对于那些想说: 我可以说,如果我把想要从中删除药品的提炼器捆绑起来,我就没有问题去做。 当我发现一个药箱时,我会找下一个药箱检查。 我不需要第二位推手。

最佳回答

我找到了一种超立法的解决办法,它有两阵列,即ok,但在许多局势中却阻止了 par;

NSArray* matchingItems = [mainArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@" attributetockeck MATCHES[cd] %@ ", attributevalue]];
[mainArray removeObjectsInArray:matchingItems];
问题回答

当我需要把物体从 mu阵列中除去时,我使用后 lo。

for (NSInteger i = arrayCount - 1; i >= 0; i--) {
    // remove is OK here
}

如果你有2个阿雷拉。 两种类型的<代码>NSMUtableArray。 你可以做的是:

我将复制你想要保留的新 mu阵,然后将旧阵列分配给新阵列。

for( NSUInter i = 0, j = 0; i < array.count; i++ )
{
    if( test )
        [array removeObjectAtIndex:j];
    else
        j++;
}

这里是你可以操作的指挥线路版本中的代码,可以测试它去除每一奇数。

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{

    NSAutoreleasePool       * pool = [[NSAutoreleasePool alloc] init];
    NSMutableArray          * array = [NSMutableArray array];

    for( NSUInteger i = 0; i < 20; i++ )
        [array addObject:[NSNumber numberWithInteger:random()%100]];


    NSLog( @"%@", array );

    for( NSUInteger i = 0, j = 0; i < array.count; i++ )
    {
        if( [[array objectAtIndex:j] unsignedIntegerValue] & 1 )
            [array removeObjectAtIndex:j];
        else
            j++;
    }   

    NSLog( @"%@", array );

    [pool drain];
    return 0;
}

如果你在某一时间重新确认物体,你可以使用:

[mainArray removeObject:objectToRemove];




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签