Nimmy Nimmy - 4 months ago 6
Objective-C Question

objective-C, sort an array of strings containing string elements

Lets suppose I have an array like this

NSArray* arr = @[@"MA",@"TU",@"WE",@"TH",@"FR",@"SA",@"SA"];


And I want to sort them like this:

arr = @[@"FR",@"MA",@"TU",@"WE",@"TH",@"SA",@"SA"];

Answer
    NSMutableArray * arr = [NSMutableArray arrayWithObjects:@"MA",@"TU",@"WE",@"TH",@"FR",@"SA",@"SA", nil];
    if ([arr containsObject:@"FR"]) {
        [arr removeObject:@"FR"];
        [arr insertObject:@"FR" atIndex:0];
    }