Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nil vs kNilOptions

I find some time ago the enum kNilOptions which is equal to 0. I try to make my code the most readable but I wonder what is best to use when you have methods that take an option parameter, for example :

[NSData dataWithContentsOfFile:imageURL.path
                               options:kNilOptions
                               error:&error];

I usually see nil in a lot of code I read but I think kNilOptions would be more accurate. I don't see often (almost never) kNilOptions. Is there a reason for that?

Do you think it is ok to use it or is it better to stick to simply nil?

like image 951
Kevin Hirsch Avatar asked Jul 15 '14 12:07

Kevin Hirsch


1 Answers

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.

like image 147
trojanfoe Avatar answered Sep 23 '22 04:09

trojanfoe