Hal*_*ann 7 iphone objective-c nsmutablearray nsarray
我有一个NSArray,它给了我以下数据:
01/14/2013 13:28:06.559 IUser Reader [71164: c07] (
{
"id_acompanhante" = "";
"id_evento" = 34;
"user_id" = 1;
"inserido_por" = "Himself";
name = iUser;
status = done;
type = User;
}
{
"id_acompanhante" = 1;
"id_evento" = 34;
"user_id" = 1;
"inserido_por" = iUser;
name = "Mayara Roca";
status = naofeito;
type = companion;
}
)
Run Code Online (Sandbox Code Playgroud)
如何将此数据播放到NSMutableArray并在每个项目中添加另一个字段.例:
{
"id_acompanhante" = "";
"id_evento" = 34;
"user_id" = 1;
"inserido_por" = "Himself";
name = IUser;
status = done;
type = User;
tag = 2;
}
Run Code Online (Sandbox Code Playgroud)
我又增加了一个字段"TAG".
我该怎么做呢?
NSMutableArray *mutableArray = [NSMutableArray array];
for (NSDictionary *dictionary in yourArray) {
NSMutableDictionary *mutDictionary = [dictionary mutableCopy];
[mutDictionary setObject:[NSNumber numberWithInt:2] forKey:@"tag"];
[mutableArray addObject:mutDictionary];
}
Run Code Online (Sandbox Code Playgroud)
这是你怎么做的.使数组可变不允许您更改其中的字典的内容.您需要提取每个字典并使其变为可变,然后将其存储回数组中.
简单
NSMutableArray *mArray = [NSMutableArray arrayWithArray:yourArray]
[mArray addObject:yourObject];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9065 次 |
| 最近记录: |