开发者

"error:NULL" or "error:nil"?

开发者 https://www.devze.com 2023-04-12 21:07 出处:网络
Just trying to figure out what\'s the best practice: when using method that takes (NSError**), is it better to send it nil or NULL?

Just trying to figure out what's the best practice: when using method that takes (NSError**), is it better to send it nil or NULL?

For example,

NSArray *items = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];

I开发者_如何转开发n the documentation it says "You may specify nil for this parameter if you do not want the error information." On the other hand, since its a double pointer, NULL seems to make sense as well?


Technically, NULL is the right answer and the docs are wrong.

In practice, it matters not. NULL and nil are the same, for all intents and purposes.

While that could change and remain language compliant, it couldn't change without breaking tons and tons of stuff.

Feel free to file a bug, though.

0

精彩评论

暂无评论...
验证码 换一张
取 消