Original blog, reproduced please indicate the source
Blog.csdn.net/hello_hwc
Welcome to my iOS SDK detailed column, where there are a number of basic articles.
Http://blog.csdn.net/column/details/huangwenchen-ios-sdk.html
Preface: Warnings is a very important part of coding, the compiler gives reasonable warning to help developers to find their own code problems, to prevent a lot of bugs.
By default, creating a project with Xcode will automatically open some important warnings, but more often, we need a more complete reminder from the compiler.
iOS development uses the clang compiler.
The default warning can be found in the build settings
Searching for warnings in search, you can see that this is the warnings for all languages
Of course, you can also open warning for different languages, also in build settings
However, such a turn-off customization is good, sometimes we just need to open all or open all important warnings can
At this time, enter
You can add a few build flags to enable the warning, mostly three
1. -Wall Clang think he can accurately report the warning
2. -Wextra additional harsh warnings, these warnings do not necessarily cause errors. For example, if you use this flag, assigning the singned to unsigned triggers a warning, and most of the time it's okay to assign a value.
3. -Weverything All warnings
General items are open -Wall and -Wextra two warnings to ensure there are no serious errors, and of course, if there are obvious things that don't go wrong, you can turn off one or some of these warnings.
-Wall-Wno-unused-variable//启用Wall但是剔除unused-variable
Force a warning to be turned on or off with a statement
Force a warning to open
#warning "This method can not be used"
Force an error to open
#error "You must add this key,or you will fail"
Force a warning to close
For example
There's a warning here. Test this selector is not implemented
[selfperformSelector:@selectorwithObject:nil];
Force this warning off
#pragma clang diagnostic push#pragma clang diagnostic ignored "-Wundeclared-selector" [self performSelector:@selector(test) withObject:nil];#pragma clang diagnostic pop
Common Clang Warning
- Wall
- Wbad-function-cast
- Wcast-align
- Wconversion
- Wdeclaration-after-statement
- Wdeprecated-implementations
- Wextra
- Wfloat-equal
- wformat=2
- Wformat-nonliteral
- Wfour-char-constants
- Wimplicit-atomic-properties
- Wmissing-braces
- Wmissing-declarations
- Wmissing-field-initializers
- Wmissing-format-attribute
- Wmissing-noreturn
- Wmissing-prototypes
- Wnested-externs
- Wnewline-eof
- Wold-style-definition
- Woverlength-strings
- Wparentheses
- Wpointer-arith
- Wredundant-decls
- Wreturn-type
- Wsequence-point
- Wshadow
- Wshorten-64-to-32
- Wsign-compare
- Wsign-conversion
- Wstrict-prototypes
- Wstrict-selector-match
- Wswitch
- Wswitch-default
- Wswitch-enum
- Wundeclared-selector
- Wuninitialized
- Wunknown-pragmas
- Wunreachable-code
- Wunused-function
- Wunused-label
- Wunused-parameter
- Wunused-value
- Wunused-variable
- Wwrite-strings
Difficult mode
The so-called difficult mode is to turn on all warnings and treat warnings as error. This means that as long as there is another warning present, the program will not compile and run.
Reference links
http://onevcat.com/2013/05/talk-about-warning/
Http://programmers.stackexchange.com/questions/122608/clang-warning-flags-for-objective-c-development
Http://amattn.com/p/better_apps_clang_weverything_or_wall_is_a_lie.html
http://nshipster.cn/clang-diagnostics/
IOS Xcode Enable/disable Clang Warnings