Easy way to understand NSComparisonResult in NSDecimalNumber for newbies

So if you go straight to the documentation you’ll find out this:

// compare two NSDecimalNumbers

So deep.. ok but how do we handle something basic like fooDecimalNumber > barDecimalNumber? if you google a little bit you will find out that you can use one of the definitions in the typedef enum NSComparisonResult, in the case of NSOrderedSame everything is really clear but when it comes about NSOrderedAscending and NSOrderedDescending let’s be honest at first glance these guys are not that clear, so how do we get familiar with NSDecimalNumber comparison results ?

Behold the key of NSComparisonResult

comparision result

And if you still need to read some code

if ([fooDecimalNumber compare:barDecimalNumber]) == NSOrderedDescending {
   //fooDecimalNumber is bigger than barDecimalNumber
}
if ([fooDecimalNumber compare:barDecimalNumber]) == NSOrderedAscending {
	//fooDecimalNumber is smaller than barDecimalNumber
}
All posts