Objective-C:#define vs extern const [英] Objective-C : #define vs extern const

查看:89
本文介绍了Objective-C:#define vs extern const的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前已经问过这个问题,但我似乎无法在Apple的文档中找到有关它的信息;也许你们有些人做过。

I know this question has been asked before, but I can't seem to find information about it in Apple's documentation; maybe some of you guys did.

许多Objective-C代码在 .h 文件,使用 #define
其他人在 .m
的方法和 extern 的方法> .h file。

A lot of Objective-C code has cross-file constants in a .h file, using #define. Others use the approach of a .m with constants and extern them in the .h file.

我理解差异,包括优点和缺点,但Apple是否说明在iOS开发中使用哪一个?

I understand the difference, both pros and cons, but does Apple state which one to use in iOS development?

推荐答案

Apple的推荐 extern


定义用于通知名称和字典键等用途的字符串的常量。通过使用字符串常量,您可以确保编译器验证指定了正确的值(即,它执行拼写检查)。

Define constants for strings used for such purposes as notification names and dictionary keys. By using string constants, you are ensuring that the compiler verifies the proper value is specified (that is, it performs spell checking).

不可否认,他们有时会对此不一致。

Admittedly they are inconsistent about this sometimes.

这篇关于Objective-C:#define vs extern const的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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