iPhone SDK Objective C是否支持函数内部的功能? [英] Does iPhone SDK Objective C support functions inside of functions?

查看:163
本文介绍了iPhone SDK Objective C是否支持函数内部的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道javascript,例如支持函数内部的函数,如下所示:

I know that javascript, for example supports functions inside of functions, like so:

function doSomething(){

  function doAnothingThing(){
    //this function is redefined every time doSomething() is called and only exists inside doSomething()    
  }

  //you can also stick it inside of conditions

  if(yes){
    function doSomethingElse(){
      //this function only exists if yes is true
    }
  }


}

objective-c支持这个?理论示例:

Does objective-c support this? Theoretical example:

 -(void) doSomething:(id) sender{
   -(void) respondToEvent: (id) sender{
     //theoretically? ... please?
   }
}

BONUS:本地的正确用语是什么函数?

BONUS: What is the proper term for a "local" function?

推荐答案

通常的术语是嵌套函数。 gcc支持嵌套函数作为C的扩展(默认情况下禁用)。我认为这个选项不适用于带有gcc的Objective-C(或C ++),即使使用它也可能不是一个好主意(可移植性等)。

The usual term is nested function. gcc supports nested functions as an extension to C (disabled by default). I don't think this option is available with Objective-C (or C++) with gcc though, and even if it were it's probably not a good idea to use it (portability etc).

gcc.gnu.org/onlinedocs/gcc/Nested-Functions。 html

这篇关于iPhone SDK Objective C是否支持函数内部的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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