目标C“ #if”句法 [英] Objective C "#if" syntax

查看:105
本文介绍了目标C“ #if”句法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我看某些类时,我对 pound if或 #if 语法感到困惑。

I'm a little confused by the "pound if" or #if syntax I see when I look at some classes.

例如:

#if someConstant == someNumber
  do something
#elif
  etc

相比:

if (someConstant == someNumber) 
   do something
else if {
   do more stuff
}

有什么区别,为什么要使用 #if

what's the difference, and why use #if ?

推荐答案

#if 等是预处理程序指令。这意味着它们在编译之前而不是在运行时处理。例如,这在定义仅在为 debug 而不是 release 进行编译时才编译的调试行为时很有用:

#if etc are preprocessor directives. This means that they are dealt with before compiling and not at runtime. This can be useful, for example, in defining debugging behaviour that only compiles when you build for debug and not release:

#if DEBUG
    #define ISRelease(x) [x release]
#else
    #define ISRelease(x) [x release], x = nil
#endif

(代码由Jeff LaMarche的博客提供。)

(Code courtesy of Jeff LaMarche's blog.)

这样,您无需在提交应用程序和删除调试代码之前就遍历整个应用程序的代码。这只是使用这些指令的一个小例子。

This way you don't need to go through your entire application's code just before you submit your app and remove a load of debugging code. This is just one small example of the use of these directives.

这篇关于目标C“ #if”句法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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