踩踏时从方法"返回"?

neo*_*eye 12 xcode objective-c lldb

我想退出我正在逐步完成的当前方法.

-(void)helloWorld {
    NSLog(@"Hello");
    // I would like to return here, so that "World" isn't printed.
    NSLog(@"World");  
}
Run Code Online (Sandbox Code Playgroud)

我试过以下,但没有运气.

(lldb) expr return
<no result>
Run Code Online (Sandbox Code Playgroud)

这可能与lldb?

Jas*_*nda 18

不幸的是,在Xcode 4.5.x中,没有办法强制从函数中提前返回.在http://lldb.llvm.org/上的当前lldb源代码中,有一个新添加的命令,thread return它可以执行您想要的操作 - 它包括指定函数返回值的功能.但是,直到下一个主要版本才会出现在Xcode中.

  • 在Xcode 6中,`thread return`开箱即用 (11认同)

kub*_*uba 7

使用Xcode进行调试时,如果程序在断点处暂停,则可以将绿色小箭头拖动到函数中的任何其他行.例如,在以下代码中:

Xcode断点

如果我想跳过NSLog(@"B"),我可以简单地将绿色箭头从第20行拖到第23行,这意味着该函数将从我想要的任何地方"返回".