iqueqiorio iqueqiorio - 9 months ago 95
iOS Question

Capitalized NSArray of Strings?

I have an NSarray called array. And it look like this

array = @[@"one", @"two", @"three"];

I want this array to be capitalized. What is the best way to go about this. I can only think of making an NSMutableArray called mutableArray.

And do something like this

for(int i = 0; i < array.lenght; i++) {
self.mutableArray = addObject:[array[i] capitalizedString];

Or is there another better way?

Answer Source

The magic method you are looking for does in fact exist.

NSArray *array = @[@"one", @"two", @"three"];
NSArray *capArray = [array valueForKeyPath:@"capitalizedString"];