我正在调用一个带有布尔值的块。根据调试器,布尔值为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];
}
}];
这是情况的a screenshot,显示断点和工具提示。
答案 0 :(得分:5)
如果您处于发布而不是调试中,则很可能只是断点错误。这可能是由于编译器删除了发布中的一些语句,因为优化和行号不再与它们应该的代码排成一行。
使用NSLog
语句验证if语句的哪个子句。
另外,您提到__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
。