为什么 NSLog() 在方法返回之后不做任何事情? [英] Why does NSLog() not do anything if it's after a method's return?
本文介绍了为什么 NSLog() 在方法返回之后不做任何事情?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我注意到当我的方法运行时,控制台没有打印任何内容:
I noticed that when my method runs, nothing is printed to the console:
- (BOOL)theTemporyFunction
{
return YES;
NSLog(@"Events");
}
但是当我改变语句的顺序时:
but when I change the order of the statements:
- (BOOL)theTemporyFunction
{
NSLog(@"Events");
return YES;
}
NSLog()
确实运行了.
两个版本都可以编译,那么为什么 NSLog()
在第一个中似乎不起作用?
Both versions compile, so why doesn't NSLog()
seem to work in the first?
推荐答案
return
是在函数中执行的最后一条语句.在返回语句之后,该函数将控制权返回给调用者.
return
is the last statement that is executed in a function. After the return statement the function returns the control to the caller.
例如:
function1 function2
int x;
function2();-----------------------------+
+---->puts("function2 - should be called");
+-----return;
puts("back to function1");<--------------+ puts("should not be called");
这篇关于为什么 NSLog() 在方法返回之后不做任何事情?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文