我正在调用一个具有布尔值的块。根据调试器的说法,布尔值是false,但它似乎被视为true。这是编译器/Xcode错误,还是我应该以类似于__block
的方式标记传递给块的参数?
// Hovering over the |finished| parameter displays the value of finished as NO
[self.repDataSynchronizationClient synchronizeWithRepId:rep.id andCompletion:^(NSString * progressMessage, BOOL finished){
if( finished )
{
[self hideLoader]; // Breakpoint set here, which I am hitting
}
else
{
[self setLoaderTitle:progressMessage];
}
}];
这是一个情况的屏幕截图,其中显示了断点点击和工具提示。
如果您在发布而不是调试中,那么很有可能只是断点出错。这可能是由于编译器在优化中删除了发布中的一些语句,并且行号不再与他们应该使用的代码一致
请验证if语句使用NSLog
语句到达的子句。
在另一个注释中,您提到了__block
的使用,但实际上并没有使用它,并且似乎有一个保留循环。它可能应该是:
__block id selfReference = self;
[self.repDataSynchronizationClient synchronizeWithRepId:rep.id andCompletion:^(NSString* message, BOOL finished) {
if (finished)
{
[selfReference hideLoader];
}
else
{
[selfReference setLoaderTitle:progressMessage];
}
}];
如果使用ARC,请使用__unsafe_unretained
而不是__block
。