Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在nsmutablearray中的键中添加对象_Ios_Nsmutablearray_Nsmutabledictionary - Fatal编程技术网

Ios 在nsmutablearray中的键中添加对象

Ios 在nsmutablearray中的键中添加对象,ios,nsmutablearray,nsmutabledictionary,Ios,Nsmutablearray,Nsmutabledictionary,我有一个名为temparray的nsmutablearray。nsmutablearray有一个名为“mountains”的键。关键山脉内的物体是14、12、16、20、20、20。如何仅对等于字符串@“20”的对象添加关键“mountains”中的对象 更新2:由于受欢迎的需求,我已经使用nslog打印出了nsmutablearray。它将向您展示我一直以来描述的内容 2014-03-16 21:36:16.493 Labresults[7213:60b] temparray (

我有一个名为temparray的nsmutablearray。nsmutablearray有一个名为“mountains”的键。关键山脉内的物体是14、12、16、20、20、20。如何仅对等于字符串@“20”的对象添加关键“mountains”中的对象

更新2:由于受欢迎的需求,我已经使用nslog打印出了nsmutablearray。它将向您展示我一直以来描述的内容

2014-03-16 21:36:16.493 Labresults[7213:60b] temparray (
        {
        mountains = "20";
        cookies = "11";
        picturid = "4";
    }
        {
        mountains = "20";
        cookies = "2";
        picturid = "6";
    }
        {
        mountains = "32";
        cookies = "2";
        picturid = "9";
    }
)
更新:这是我到目前为止的资料。它可以工作,但我必须让它变得更简单、更快,让它工作的速度超过一分钟

    -(void)mountainloop {
        if (fillerstring == NULL) {
            int x = 0;
            _first = NULL;
            _second = NULL;

            NSDictionary *itemAtIndex =(NSDictionary *)[temparray objectAtIndex:x];
            _first = [itemAtIndex objectForKey:@"mountains"];
            if ([_first isEqualToString:@"20"]) {
            float a = [_first floatValue];
            k = [NSNumber numberWithFloat: a];
}     
            x = x + 2;//make +2
            if (([temparray count] < x)) {
                _allmonthdail.text = [NSString stringWithFormat:@"%.2f", _allmonthdail.text, a];
                temparray = NULL;         
            }
            else {
                x = x - 1;
                e = &x ;
                fillerstring = @"noo";       
                [self mountainloop];
            } 

        }
        else {
            int x= *(e);
            _first = NULL;

            NSDictionary *itemAtIndex =(NSDictionary *)[temparray objectAtIndex:x];
            _first = [itemAtIndex objectForKey:@"mountains"];
            if ([_first isEqualToString:@"20"]) {

            float a = [_first floatValue];
            float myfloatvalue = [k  floatValue];
            k = [NSNumber numberWithFloat: a + myfloatvalue];  
}       
            x = x + 2;
            if (([temparray count] < x)) {           
                float u = [k floatValue];
                _allmonthdail.text = [NSString stringWithFormat:@"%.2f", _allmonthdail.text, u];
                temparray = NULL;         
            }
            else {
                x = x - 1;
                e = &x ;
                fillerstring = @"noo";               
                [self mountainloop];
            }}      
    }
-(无效)mountainloop{
if(fillerstring==NULL){
int x=0;
_第一个=空;
_第二个=空;
NSDictionary*itemAtIndex=(NSDictionary*)[temparray objectAtIndex:x];
_first=[itemAtIndex objectForKey:@“mountains”];
if([[第一个等位字符串:@“20”]){
浮点a=[[第一个浮点值];
k=[NSNumber numberWithFloat:a];
}     
x=x+2;//make+2
if(([temparray count]
试试这个

NSIndexSet *indxs = [temparray indexesOfObjectsPassingTest:^BOOL(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
        return [obj[@"mountain"] isEqualToString:@"20"];
    }];

NSInteger sum = 20 * indxs.count;

删除一个坏问题并发布一个新的坏问题是不合适的。相反,你应该更新这个问题,让它有意义,让其他人都清楚。这个问题和上一个问题一样令人困惑。数组没有键。请发布您的数据结构示例。
objectForKey:
NSDictionary
上的一个方法,而不是
NSArray
。不,它们没有-数组可以将字典作为其单独的元素,这些字典可以有键,但数组没有键。这就是为什么我们要求您发布阵列的打印输出,以便我们了解您拥有的内容。如果您只需按照Josh和我的要求发布阵列(或其中的一部分)的打印输出,我们中的任何人都可以帮助您。