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)];
}];

```
If you create your sort descriptor with `initWithKey:ascending:selector:` or `sortDescriptorWithKey:ascending:comparator:` you can specify a selector used to compare objects.

Now the problem is which selector to pass. Well, you can create a Category on NSString implementing a custom sort function that sorts based on the numeric value of the string. Remember that from the documents:

> 
> The selector must specify a method implemented by the value of the
>  property identified by keyPath. The selector used for the comparison
>  is passed a single parameter, the object to compare against self, and
>  must return the appropriate NSComparisonResult constant. The selector
>  must have the same method signature as:
> 
> 
> 

```
- (NSComparisonResult)localizedCompare:(NSString *)aString

```

> 
> The object at the specified property key, relative to each object in
>  the collection, must implement the compare selector used to create the
>  sort descriptor. If no custom selector was specified, the objects must
>  implement compare.
> 
> 
>