调试器将BOOL块参数的值报告为NO,但我的if语句的计算结果为true

ary*_*axt 0 debugging xcode objective-c objective-c-blocks

我正在调用一个布尔值的块.根据调试器,布尔值为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];
    }
}];
Run Code Online (Sandbox Code Playgroud)

这是情况的屏幕截图,其中显示了断点命中和工具提示.

Jam*_*ter 5

如果您处于发布而不是调试中,那么很可能它只是错误断点.这可能是由于编译器在发布中删除了一些语句,因为优化和行号不再与它们应该的代码排成一行.

验证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];
    }
}];
Run Code Online (Sandbox Code Playgroud)

如果使用ARC,请使用__unsafe_unretained而不是__block.