当我编译语句[[NSArray alloc] init];
时,clang给出“警告:表达式结果未使用[-Wunused-value]”。
如何从我自己的功能中导致“表达结果未使用”警告?例如:
@interface SimplePromise : NSObject
-(SimplePromise*)then:(id(^)(id result))block;
@end
-(void)someMethod {
// I want this statement to cause a warning because
// the transformed promise is dealloc’d before the block ever executes!
[self.fetchPromise then:^id(id result) {
self.fetchedData = result;
return nil;
}];
}
答案 0 :(得分:5)
使用__attribute__((warn_unused_result))
声明您的方法:
-(SimplePromise*)then:(id(^)(id result))block __attribute__((warn_unused_result));