简体   繁体   English

Xcode Breakpoint:文件名或类名的快捷方式

[英]Xcode Breakpoint: shortcut for file name or class name

When setting a breakpoint in Xcode there is the %B shortcut.在 Xcode 中设置断点时,有%B快捷方式。 Placed into the "Log message" it will print the breakpoint name to the console.放入“日志消息”中,它将把断点名称打印到控制台。 The breakpoint name will be the method name. breakpoint name将是方法名称。

So creating a breakpoint in - (void)viewDidLoad will print所以在- (void)viewDidLoad创建断点将打印

-viewDidLoad

When the breakpoint stops all is clear.当断点停止时,一切就清楚了。 But when the app continues after evaluating just viewDidLoad printed in the debug console won't tell which Class was called.但是当应用程序在评估调试控制台中打印的viewDidLoad后继续运行时,不会告诉调用了哪个类。 viewDidLoad could be in every ViewController. viewDidLoad可以在每个 ViewController 中。 So I add the class name to identify the location (see image).所以我添加了类名来标识位置(见图)。

To avoid having to type the full class name I use initials: MGA_OneViewController becomes OVC为了避免输入完整的类名,我使用首字母缩写: MGA_OneViewController变为OVC

Breakppint 与日志消息“OVC %B”

The OVC %B produces the output OVC %B产生输出

OVG -viewDidLoad

and now the Class is known.现在班级是已知的。

Typing three (or a few) letters is not a problem but is does require discipline to ensure the same acronym is used through out the class.键入三个(或几个)字母不是问题,但确实需要纪律以确保在整个课程中使用相同的首字母缩略词。

I found a nice syntax but that is even longer, Craig uses p (void)NSLog(@"%s: %@", _cmd)我发现了一个很好的语法,但它更长,Craig 使用p (void)NSLog(@"%s: %@", _cmd)

Some related SO questions ( 16661758 , 12695845 ) all use a rather long command, too long for me to remember.一些相关的 SO 问题( 1666175812695845 )都使用了相当长的命令,太长了我记不清了。

So my questions are: is the there a percent shortcut for the class name?所以我的问题是:类名是否有百分比快捷方式? A Percent-F maybe?可能是Percent-F Alternatively, is it possible to create a breakpoint template that will contain the expressions ready made?或者,是否可以创建一个包含现成表达式的断点模板?

我使用@[self class]@ %B ,虽然它不是格式化程序,但可能比原始问题中列出的替代方案更紧凑。

为了快速,您可以使用

@type(of:self)@

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM