NSRangeMake

Maybe this is common and maybe it’s not, but in the course of my work writing Objective-C for iOS, I end up using CGRectMake()—to make, yes, a CGRect—pretty frequently, but I only rarely need to build an NSRange.  So following the CGRectMake pattern, I inevitably start typing “NSRangeMake” and along the way the only method completion I get is for NSRangeFromString().  A few befuddled minutes later, I realize that what I’m looking for is NSMakeRange(), and then I can go back to slowly forgetting about that reversed word order until I run in to the same problem a month or two later.  Since I really my start programming in PHP, this kind of thing shouldn’t throw me, but it does.

So on the off chance that this happens to you, too, here you go:

#define NSRangeMake(location, length) NSMakeRange(location, length)

I wouldn’t recommend actually using NSRangeMake() in code anywhere, but this will at least give you a little reminder.

Leave a comment

Your email address will not be published. Required fields are marked *