本文介绍了iOS-将数组对象复制到另一个对象中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题,我需要帮助.

I have a little problem, and I need help.

我想遍历多维数组,并且每次找到键ex."name"的值都等于ex. 你好".我想将该数组对象复制到另一个数组中.

I want to loop through a multidimensional array, and every time I find a value for a key ex."name" that is equal to ex. "Hello". I want to copy that array object into another array.

我该怎么做?

推荐答案

我假设您有一个二维数组,并且由于我不知道数组中的对象看起来像我采用的是id类型,方法valueForKey:

I assume you have a 2-dimensional array and since I don't know how your objects within the array look like I take the id type and the method valueForKey:

 NSMutableArray *tmp = [[NSMutableArray alloc] init];
 for(NSArray *dim1Array in yourMultidimensionalArray)
 {
    for(id obj in dim1Array)
    {
       if([[obj valueForKey:@"name"] isEqualToString:@"Hello"])
       {
          [tmp addObject:dim1Array];
          break; // I assume you only want to add it once
       }
    }
 }

这篇关于iOS-将数组对象复制到另一个对象中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:12