-2

次のような配列があります。

(
  {
    id = 4;
    name = "AAAA";
  },

  {
    id = 5;
    name = "BBBB";
   },
 {  
    id = 9;
    name = "BBBB";
   }
)

id=5 の名前を変更するにはどうすればよいですか?

4

2 に答える 2

1
    suppose Array = (
      {
        id = 4;
        name = "AAAA";
      },

      {
        id = 5;
        name = "BBBB";
       },
     {  
        id = 9;
        name = "BBBB";
       }
    )

    //Now to change the name where the id=5

    NSMutableDictionary *dict = [array objectAtIndex: 1];
    [dict setObject :@"hari kishan" forKey:@"name'];//this will change the name where id = 5
//Or if want to make dynamic

-(void)changeNameForId:(NSString*)id
{
for(NSMutableDictionary *dictionary in array)
{
    if([[dictionary objectForKey:@"id" isEqualToString :id]){
        [dictionary setObject:@"hari kishan" forKey@"name"]
    }
}

}

于 2013-07-26T05:21:46.627 に答える