在iOS開發(fā)過(guò)程中, 我們可能會(huì)碰到一些系統(tǒng)方法棄用, weak锌云、循環(huán)引用、不能執(zhí)行之類的警告医瘫,運(yùn)用clang標(biāo)注可以幫助你輕松解決猾骡。
// 插入需要忽略的相關(guān)代碼 ??
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
//插入需要忽略的相關(guān)代碼(test方法在本類中不存在,ignored后加入"-Wundeclared-selector"編譯器便忽略了此警告蚜印。)
[one performSelector:@selector(test) withObject:nil afterDelay:2.0];
#pragma clang diagnostic pop
//方法棄用告警 ??
#pragmaclang diagnostic push
#pragmaclang diagnostic ignored "-Wdeprecated-declarations"
UIAlertView *alertViewTmp = [[UIAlertView alloc]initWithTitle:@""message:@""delegate:nil cancelButtonTitle:@""otherButtonTitles:@"", nil];
[alertViewTmp show];
#pragmaclang diagnostic pop
// 不兼容指針類型 ??
#pragmaclang diagnostic push
#pragmaclang diagnostic ignored "-Wincompatible-pointer-types"
//
#pragmaclang diagnostic pop
//循環(huán)引用 ??
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
// self.completionBlock = ^ {//...// };
#pragma clang diagnostic pop
// 未使用變量 ??
#pragmaclang diagnostic push
#pragmaclang diagnostic ignored "-Wunused-variable"
// inta;
#pragmaclang diagnostic pop
// 未使用default ??
#pragmaclang diagnostic push
#pragmaclang diagnostic ignored "-Wcovered-switch-default"
// switch (style) {
// case UITableViewCellStyleDefault:
// case UITableViewCellStyleValue1:
// case UITableViewCellStyleValue2:
// case UITableViewCellStyleSubtitle:
// // ...
// default:
// return;
// }
#pragmaclang diagnostic pop
大家可以搜索需要忽略的警告編號(hào)莺禁,替換-Wundeclared-selector。(以下部分僅供參考)
-Wformat? ? invalid position specified for %select{field width|field precision}0
-Wformat? ? cannot mix positional and non-positional arguments in format string
-Wformat? ? values of type '%0' should not be used as format arguments add an explicit cast to %1 instead
-Wformat? ? format specifies type %0 but the argument has type %1
-Wformat? ? zero field width in scanf format string is unused
-Wformat? ? no closing ']' for '%%[' in scanf format string
-Wformat? ? format string should not be a wide string
-Wformat? ? format string contains '\\0' within the string body
-Wformat? ? '%select{*|.*}0' specified field %select{width|precision}0 is missing a matching 'int' argument
-Wformat? ? field %select{width|precision}0 should have type %1, but argument has type %2
-Wformat? ? %select{field width|precision}0 used with '%1' conversion specifier, resulting in undefined behavior
-Wformat? ? format string missing
-Wformat? ? incomplete format specifier-Wformat? ? flag '%0' results in undefined behavior with '%1' conversion specifier
-Wformat? ? flag '%0' is ignored when flag '%1' is present-Wformat? ? more '%%' conversions than data arguments
-Wformat? ? length modifier '%0' results in undefined behavior or no effect with '%1' conversion specifier
-Wformat-extra-args? ? data argument not used by format string
-Wformat-invalid-specifier? ? invalid conversion specifier '%0'
-Wformat-nonliteral? ? format string is not a string literal
-Wformat-security? ? format string is not a string literal (potentially insecure)
-Wformat-zero-length? ? format string is empty
-Wgcc-compat? ? GCC does not allow the 'cleanup' attribute argument to be anything other than a simple identifier
-Wglobal-constructors? ? declaration requires a global constructor
-Wglobal-constructors? ? declaration requires a global destructor
-Wgnu-conditional-omitted-operand? ? use of GNU ?: conditional expression extension, omitting middle operand
-Wheader-hygiene? ? using namespace directive in global context in header
-Widiomatic-parentheses? ? using the result of an assignment as a condition without parentheses
-Wignored-attributes? ? 'malloc' attribute only applies to functions returning a pointer type
-Wignored-attributes? ? %0 attribute only applies to %select{functions|unions|variables and functions|functions and methods|parameters|functions, methods and blocks|functions, methods, and classes|functions, methods, and parameters|classes|variables|methods|variables, functions and labels|fields and global variables|structs|variables, functions and tag types|thread-local variables|variables and fields|variables, data members and tag types|types and namespaces|Objective-C interfaces}1
-Wignored-attributes? ? '%0' attribute cannot be specified on a definition
-Wignored-attributes? ? __weak attribute cannot be specified on an automatic variable when ARC is not enabled
-Wignored-attributes? ? Objective-C GC does not allow weak variables on the stack
-Wignored-attributes? ? __weak attribute cannot be specified on a field declaration
-Wignored-attributes? ? attribute %0 cannot be applied to %select{functions|Objective-C method}1 without return value
-Wignored-attributes? ? attribute declaration must precede definition
-Wignored-attributes? ? attribute %0 is ignored, place it after \"%select{class|struct|union|interface|enum}1\" to apply attribute to type declaration
-Wignored-attributes? ? __declspec attribute %0 is not supported
-Wignored-attributes? ? attribute %0 ignored, because it cannot be applied to a type
-Wignored-attributes? ? attribute %0 after definition is ignored
-Wignored-attributes? ? %0 attribute ignored
-Wignored-attributes? ? 'sentinel' attribute only supported for variadic %select{functions|blocks}0
-Wignored-attributes? ? 'sentinel' attribute requires named arguments
-Wignored-attributes? ? '%0' only applies to %select{function|pointer|Objective-C object or block pointer}1 types type here is %2
-Wignored-attributes? ? 'nonnull' attribute applied to function with no pointer arguments
-Wignored-attributes? ? %0 attribute can only be applied to instance variables or properties
-Wignored-attributes? ? ibaction attribute can only be applied to Objective-C instance methods
-Wignored-attributes? ? %0 calling convention ignored on variadic function
-Wignored-attributes? ? %0 only applies to variables with static storage duration and functions
-Wignored-attributes? ? %0 attribute argument not supported: %1
-Wignored-attributes? ? #pramga ms_struct can not be used with dynamic classes or structures
-Wignored-attributes? ? transparent union definition must contain at least one field transparent_union attribute ignored
-Wignored-attributes? ? first field of a transparent union cannot have %select{floating point|vector}0 type %1 transparent_union attribute ignored
-Wignored-attributes? ? 'gnu_inline' attribute requires function to be marked 'inline', attribute ignored