如何将一个NSMutableArray复制到另一个NSMutableArray [英] How to Copy one NSMutableArray to another

查看:97
本文介绍了如何将一个NSMutableArray复制到另一个NSMutableArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有值firstname和id的nsmutablearray(xmlParseArray),我想只将firstname复制到另一个nsmutablearray(copyArray)。我怎么能这样做我想尝试更多但尚未结果请给我一些关于taht的想法。

I have an nsmutablearray(xmlParseArray) having values firstname and id, i want to copy only firstname into another nsmutablearray(copyArray). how can i do this i am trying more but not yet result please give me some idea about taht.

提前致谢:

推荐答案

我猜你的意思是第一个数组 xmlParseArray 包含一个 NSDictionary 每个对象都附加了对象firstname和id的对象。实现这一目标的一种方法是:

I'm guessing you mean that the first array, xmlParseArray, contains a list of NSDictionary objects which each have objects attached to the keys "firstname" and "id". One way to accomplish that would be like this:

NSMutableArray *copyArray = [[NSMutableArray alloc] initWithCapacity:[xmlParseArray count]];
for(NSDictionary *dict in xmlParseArray)
    if([dict objectForKey:@"firstname"])
        [copyArray addObject:[dict objectForKey:@"firstname"]];

// ...do whatever with copyArray...
[copyArray release];

这篇关于如何将一个NSMutableArray复制到另一个NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆