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
}

```
The *-sortedArrayUsingSelector:* method in your example calls the *-compare:* method on the objects in the array. For some objects Apple has already implemented a *-compare:* method, for example if you read through [the NSString documentation](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/uid/20000154-compare_), you'll find a *-compare:* method implemented. You can also call custom comparison methods on your own custom objects if you've implemented a comparison method in these objects. Please note the comparison method doesn't have to be called *-compare:*, of importance is only the return value (NSComparisonResult) and the object the method receives.