避免在块中使用"表达结果未使用"警告

Mar*_*ack 23 warnings clang objective-c-blocks

以下代码在块中的赋值操作上返回表达式未使用的警告.代码不是很实用,但在排除部分中有更多代码,并且代码必须在特定队列上运行.

__block NSNumber *pageId=nil;
dispatch_sync(_myDispatchQueue, ^{
    int val;
    //... code generates an int and puts it in val
    pageId = [NSNumber numberWithInt:val];
}];
//pageId used below
Run Code Online (Sandbox Code Playgroud)

我该如何摆脱这个错误?

Mat*_*son 47

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-value"
 pageId = [NSNumber numberWithInt:val];
#pragma clang diagnostic pop
Run Code Online (Sandbox Code Playgroud)