0

Was wondering how i would change the first value of "Jeremy Arimado" into a different string?

crewData = @[
                @{
                    @"roleNameAr": @"Jeremy Arimado",
                    @"rolePhoneAr":@"123456",
                    },
                @{
                    @"roleNameAr": @"Jeremy Arimado 2",
                    @"rolePhoneAr":@"123456",
                    },
                @{
                    @"roleNameAr": @"Jeremy Arimado 3",
                    @"rolePhoneAr":@"123456",
                    }
                ];
Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
Jeremy
  • 43
  • 1
  • 9

1 Answers1

2

The @[] literal produces an NSArray instance, which is immutable. In the same way @{} produces an NSDictionary, immutable as well.

You have to obtain a mutable copy of the objects, before being able to modify it.

NSMutableArray *mutableCrewData = [crewData mutableCopy];
NSMutableDictionary *mutableCrewMember = [mutableCrewData[0] mutableCopy];
mutableCrewMember[@"roleNameAr"] = @"Foo Bar";
mutableCrewData[0] = mutableCrewMember;
crewData = mutableCrewData;

An alternative would be to directly use NSMutableDictionary and NSMutableArray, but you cannot directly use the literal syntax for that.

Community
  • 1
  • 1
Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235