首先#pragma在本质上是声明,常用的功能就是注释,尤其是给Code分段注释;而且它还有另一个强大的功能是处理编译器警告,但却没有上一个功能用的那么多。
clang diagnostic 是#pragma 第一个常用命令:
class="hljs undefined">#pragma clang diagnostic push
#pragma clang diagnostic ignored "-相关命令"
// 你自己的代码
#pragma clang diagnostic pop
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wincompatible-pointer-types" // #pragma clang diagnostic pop
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wincompatible-pointer-types" // #pragma clang diagnostic pop
// completionBlock is manually nilled out in AFURLConnectionOperation to break the retain cycle. #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-retain-cycles" self.completionBlock = ^ { ... }; #pragma clang diagnostic pop
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-variable" int a; #pragma clang diagnostic pop
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wcovered-switch-default" // switch (style) { // case UITableViewCellStyleDefault: // case UITableViewCellStyleValue1: // case UITableViewCellStyleValue2: // case UITableViewCellStyleSubtitle: // // ... // default: // return; // } #pragma clang diagnostic pop