Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 208
iqueqiorio Avatar asked Oct 28 '14 01:10

iqueqiorio


2 Answers

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

NSArray *array = @[@"one", @"two", @"three"];
NSArray *capArray = [array valueForKeyPath:@"capitalizedString"];
like image 190
Krys Jurgowski Avatar answered Sep 17 '22 21:09

Krys Jurgowski


SWIFT

You Can use map

let array = ["one", "two", "three"]
let upercaseArray = array.map({$0.uppercased()})

now you have upercaseArray like ["ONE","TWO","THREE""]

like image 35
jagdeep singh Avatar answered Sep 20 '22 21:09

jagdeep singh