nil vs kNilOptions

I think 0 is more readable than kNilOptions and there is some evidence that kNilOptions is "old".

You should use nil to represent uninitialized Objective-C object references and NULL for uninitialized C pointers (void *, char *, etc).

Use 0 if the options doesn't provide a "none value", which is the case for options NSDataReadingOptions.


kNilOptions is an old constant intended to document that the 0 is not just any magic zero, but stands for “no options”. In that sense its use is valid, although personally I consider it quite ugly in an Objective-C context (most of its use seems to be in C) with the k prefix and all. Searching developer.apple.com for options:kNilOptions vs options:0 also shows that options:0 is their preferred style.

As for nil, it is the Objective-C equivalent of a null pointer for objects, and should not be used to stand in for the number 0 (as would be the case here).

When the argument is an enum type that includes its own “no options” value, you should use that, but in case of NSData the argument is not an enum but a typedef'd NSUInteger, and it does not have its own “no options” value defined.