Q:

Sort array first string than numbers

I want to sort array that contains string as well as number like A,B,1 A,2 A,V,Z,10 B I want to sort in this way A,B,V,Z,1 A,2 A,10 B. I have search on stack overflow but nothing found useful.
Please help...

A:

Try below code:
NSArray *arr = @[@"A",@"B",@"Y",@"4 B",@"1 A",@"2 A",@"V",@"Z",@"10 B"];

NSArray *sortedArray;
sortedArray = [arr sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
    int aa = [a intValue];
    int bb = [b intValue];

    if (aa !=0 && bb != 0)
    {
        return (aa > bb);
    }
    if (aa == 0 && bb == 0)
    {
        return [a compare:b];
    }
    if (aa == 0) return -1;
    return 1;

}];

Output : (A,B,V,Y,Z,1 A,2 A,4 B,10 B)

