objective c - changing a key name in NSDictionary -
i have method returns me nsdictionary keys , values. need change key names dictionary new key name values need same key,but stuck here.need help
this method work mutable dictionary. doesn't check should done if new key exists.
you can mutable dictionary of immutable calling mutablecopy on it.
- (void)exchangekey:(nsstring *)akey withkey:(nsstring *)anewkey inmutabledictionary:(nsmutabledictionary *)adict { if (![akey isequaltostring:anewkey]) { id objecttopreserve = [adict objectforkey:akey]; [adict setobject:objecttopreserve forkey:anewkey]; [adict removeobjectforkey:akey]; } }
Comments
Post a Comment