零vs kNilOptions [英] nil vs kNilOptions

查看:280
本文介绍了零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?

推荐答案

我认为0kNilOptions更具可读性,并且有

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).

如果options没有提供无值",请使用0,例如

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

这篇关于零vs kNilOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆