零vs kNilOptions [英] nil vs kNilOptions
问题描述
我前一段时间发现枚举kNilOptions
等于0.
我试图使代码更具可读性,但是我想知道当您使用带有选项参数的方法时最好使用什么,例如:
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];
我通常在阅读的许多代码中看到nil
,但我认为kNilOptions
会更准确.我很少见(几乎从未见过)kNilOptions
.有什么理由吗?
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?
您认为可以使用它还是坚持使用nil
更好?
Do you think it is ok to use it or is it better to stick to simply nil
?
推荐答案
I think 0
is more readable than kNilOptions
and there is some evidence that kNilOptions
is "old".
您应该使用nil
代表未初始化的Objective-C对象引用,并使用NULL
代表未初始化的C指针(void *
,char *
等).
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
.
这篇关于零vs kNilOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!