0

I have a NSMutableArray below like this

(
   {
    Realimg = "<UIImage: 0x13951b130>, {800, 600}";
    "bid_accepted" = 1;
    "bid_amount" = 100;
    "bid_amount_num" = 100;
    "bid_cur_name" = USD;
    "bid_cur_symb" = $;
    "bid_currencycode" = 4;
    "bid_date" = "05 Nov 2015";
    "bid_msg" = testing;
    "bid_user_id" = 2;
    "nego_id" = 612;
    "pas_count" = 5;
    "ride_address" = "Sample Address";
    "ride_cover_img" = "uploadfiles/UploadUserImages/2/mobile/21426739600s-end-horton-plains.jpg";
    "ride_id" = 149;
    "ride_name" = "Ride to the World's End";
    "ride_type_id" = 0;
    "ride_type_name" = Travel;
    "ride_user_fname" = Nik;
    "ride_user_id" = 2;
    "ride_user_lname" = Mike;
   }

)

What I want to do is, replace the "bid_currencycode" = 4; by a different value.I want to replace 4 by 5. How can I do this? Please someone help me.

Thank you

user3182143
  • 9,459
  • 3
  • 32
  • 39
user1960169
  • 3,533
  • 12
  • 39
  • 61

2 Answers2

6

You can use the following code for doing the same:

// Getting the dictionary from your array and making it to a mutable copy
NSMutableDictionary *dict = [yourArray[index] mutableCopy];

// Changing the specified key
[dict setObject:@(5) forKey:@"bid_currencycode"];

// Replacing the current dictionary with modified one
[yourArray replaceObjectAtIndex:index withObject:dict];

Here:

  • yourArray is a NSMutableArray
  • index is a valid index (index of object, that you need to change the value)
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
1

Refer the below coding

NSMutableDictionary *dict =[[NSMutableDictionary alloc]init];

//your array

dic =[yourArray objectAtIndex:0];

[dict removeObjectForKey:@"bid_currencycode"];

[dict setObject:@“5” forKey:@"bid_currencycode"];

[yourArray replaceObjectAtIndex:0 withObject:dict];

0 is (yourArray index number) You can change according your array index number

Lalit kumar
  • 1,797
  • 1
  • 8
  • 14