Question: I have an `NSArray` of `NSDictionaries`. In the `NSDictionary` I have an element called 'rowID' which is saved as an `NSString`. However, everything saved in it is a number even though they saved as a string.

I would like to know how to sort the array based on this value but in terms of sorting 1-100. Currently, when I sort it 10 comes first when it should be 1-10.

This is how I am sorting:

```
NSArray *tempSortedItemsArray = [itemArray sortedArrayUsingDescriptors:
                                     @[[NSSortDescriptor
                                        sortDescriptorWithKey:@"rowID" ascending:YES]]];

```

Answer: 
Try this :-

```
NSArray *aSortedArray = [itemArray sortedArrayUsingComparator:^(NSMutableDictionary *obj1,NSMutableDictionary *obj2) {
    NSString *num1 =[obj1 objectForKey:@"rowID"];
    NSString *num2 =[obj2 objectForKey:@"rowID"];
    return (NSComparisonResult) [num1 compare:num2 options:(NSNumericSearch)];
}];

```
Try like this :-

```
NSDictionary *row1 = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"rowId",nil];
NSDictionary *row2 = [NSDictionary dictionaryWithObjectsAndKeys:@"2",@"rowId",nil];
NSDictionary *row3 = [NSDictionary dictionaryWithObjectsAndKeys:@"3",@"rowId",nil];

NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:row1,row2,row3,nil];

NSSortDescriptor *desc = [[NSSortDescriptor alloc] initWithKey:@"rowId" ascending:YES];
[arr sortUsingDescriptors:[NSArray arrayWithObject:desc]];

// before sort
NSLog(@"Before %@",arr);
[arr sortedArrayUsingComparator:^(NSDictionary *item1, NSDictionary *item2) {
    NSString *first = [item1 objectForKey:@"rowId"];
    NSString *second = [item2 objectForKey:@"rowId"];
    return [first compare:second options:NSNumericSearch];
}];
// After sort
NSLog(@"After %@",arr);

```