Question: I am still new to objective-c and am trying to figure out what this statement is doing exactly.

```
[names allKeys] sortedArrayUsingSelector:@selector(compare:)];

```

I know that `allKeys` is getting all the keys from my dictionary. I know that `sortedArrayUsingSelector` is sorting my array im creating. Then im calling the compare method, that is where I am lost what is this doing? From the document on apple it says that "Returns an NSComparisonResult value that indicates whether the receiver is greater than, equal to, or less than a given number." I dont understand how it is sorting based of that method.

Answer: 
```
- (NSComparisonResult)compare:
{
    // if (value of firstObject) < (value of secondObject)
        // return NSOrderedAscending
    // else if (value of firstObject) == (value of secondObject)
        // return NSOrderedSame
    // else
        // return NSOrderedDescending
}

```
You should probably be using `caseInsensitiveCompare:` in this situation since you are most likely ordering an array of strings (keys from a dictionary). 

You've assumed that sortedArrayUsingSelector is somehow separate to the `compare:` part of the code. This is not the case. `compare:` *is* the selector that is used to sort the array. 

The sorting method gives you back an array where each element, when sent the specified selector and the next element in the array, gives the correct sort order.

How NSArray achieves this is not public but at root, the selector you define is used to compare pairs of objects from within the array, the result of which informs their placement in the sorted array.