13

我正在使用带有操作“日志消息”的断点,并且我想打印 NSIndexPath 的行。所以我尝试了:cell row @indexPath.row@但没有打印出来。我也尝试使用调试器命令:expr (void)NSLog(@"indexPath row:%i", indexPath.row)但出现错误:error: property 'row' not found on object of type 'NSIndexPath *'

我究竟做错了什么?

4

3 回答 3

27

The dot syntax is just syntactic sugar added by the compiler. I've always disagreed with adding it to Objective-C, but some people love it. What you have to remember is that these dots are getting converted into method calls by the compiler, so when you message something directly, like in the debugger, you must use the actual method call. Try rewriting your expression:

expr (void)NSLog(@"indexPath row: %ld", (long int)[indexPath row])

I'm not sure if the debugger's basic log method will execute method calls like this, so you may have to use the expression type.

于 2012-07-08T20:01:16.973 回答
21

我认为这是一个特例。下面的代码将起作用,但前提row是初始化为某个值。

(lldb) print (NSInteger)[indexPath row]

我认为这可能与 row 属性是 UIKit 中 NSIndexPath 的扩展并作为该类上的类别实现的事实有关。

于 2012-11-23T12:00:14.750 回答
2

尝试在 Xcodes 变量视图中设置此摘要格式:

section:{(int)[$VAR section]},row:{(int)[$VAR row]}
于 2013-09-03T13:08:01.290 回答