Objective-C : #define vs extern const

后端 未结 4 920
时光说笑
时光说笑 2021-02-19 22:37

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.

A lot of Objective-C co

4条回答
  •  孤街浪徒
    2021-02-19 23:23

    The trouble with using #defines over an extern, is that the compiler doesn't get to do any type checking. If you #define a string, there is nothing to stop you using it where you actually want, say, a number. If you use a static NSString instead, the compiler will emit a warning if you try to use it somewhere where it isn't expecting a string.

提交回复
热议问题