开发一个项目时,难免会产生很多警告,一些是第三方或是老代码不再被支持造成的,但并不影响使用,这些警告其实可以直接隐藏掉!还有一些警告可能是系统方法弃用、不兼容指针类型、未使用变量、未使用default、weak、循环引用、不能执行之类的警告。
一、首先说下我使用CocoaPods在管理我的第三方,最近在升级的时候,把一些第三方直接升到了最新版本,结果现在使用的一些方法就出现了警告,所以这里建议在CocoaPods引入第三方时,写固定的版本,这样就可以根据自己的需求来决定是否更新最新版本。
二、删除不用的图片资源后,build后会有“xx is misssing from working copy” 的问题
方法一:
Xcode->Preferences->Source->Enable Source Control 勾勾去掉 就是禁用Xcode自带的Source Control Manager(SCM)
方法二:
在项目中提交过svn或Git后,再在本机上删除不用的图片资源后,build后会有 ”xx“is missing from working copy 的警告。
直接在终端下用svn命令删除missing的文件:(需要cd到提示你missing 文件的路径下)
svn delete nameOfMissingFile
或用Git(如果你用的是Git的话)
git rm nameOfMissingFile
就这样,cd到missing文件的路径下,然后用相应的命令(svn或git),两行命令解决问题!
三、Xib的警告
解决方案:选中xib的文件,根据下图,最后在Builds for 选中 Project Deployment Target
四、Images.xcassets相关
Images.xcassets/: warning: Missing Content: The file "xx.png" for the image set "xx" does not exist.
解决办法:
1、查找到该AppIcon对应的JSON 文件 Images.xcassets --->AppIcon.appiconset ---> Contents.json
2、右击 用Xcode 打开。 对比查找那些是你没有赋值添加图片的子 字典,将它 删除。
3、保存文件,关闭JSON 文件,再次 运行 Xcode ,OK ,问题解决。
五、
去掉xcode编译warning:ld: warning: directory not found for option '
1、选择工程, 编译的 (targets)
2、选择 Build Settings 菜单
3、查找 Library Search Paths 和 Framework Search Paths, 删掉编译报warning的路径即OK
六、最后再说下#pragma
#pragma本质上是声明,一般常用功能用来注释,它还有一个强大的功能就是处理编译器的警告,只是不太常用而已,但是在代码中处理警告还是极其高效的。
基本的语句
clang diagnostic 是#pragma 第一个常用命令:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-相关命令"
// 你自己的代码
#pragma clang diagnostic pop
例如下边是我在调用宏的时候出现的警告,其实不会照成什么影响
直接屏蔽这个警告
同理, 大家可以在下边搜索到对应的警告, 直接把对应的字符串按照上边的方式进行修改就可以了
我会不断地更新我在程序中遇到的警告,请喜欢的关注下哦
Semantic Warnings
Warning | Message |
---|---|
-WCFString-literal | input conversion stopped due to an input byte that does not belong to the input codeset UTF-8 |
-WNSObject-attribute | __attribute ((NSObject)) may be put on a typedef only, attribute is ignored |
-Wabstract-vbase-init | initializer for virtual base class %0 of abstract class %1 will never be used |
-Waddress-of-array-temporary | pointer is initialized by a temporary array, which will be destroyed at the end of the full-expression |
-Warc-maybe-repeated-use-of-weak | "weak %select{variable|property|implicit property|instance variable}0 %1 may be accessed multiple times in this %select{function|method|block|lambda}2 and may be unpredictably set to nil assign to a strong variable to keep the object alive |
-Warc-non-pod-memaccess | %select{destination for|source of}0 this %1 call is a pointer to ownership-qualified type %2 |
-Warc-performSelector-leaks | performSelector may cause a leak because its selector is unknown |
-Warc-repeated-use-of-weak | "weak %select{variable|property|implicit property|instance variable}0 %1 is accessed multiple times in this %select{function|method|block|lambda}2 but may be unpredictably set to nil assign to a strong variable to keep the object alive |
-Warc-retain-cycles | capturing %0 strongly in this block is likely to lead to a retain cycle |
-Warc-unsafe-retained-assign | assigning retained object to unsafe property object will be released after assignment |
-Warc-unsafe-retained-assign | assigning %select{array literal|dictionary literal|numeric literal|boxed expression|should not happen|block literal}0 to a weak %select{property|variable}1 object will be released after assignment |
-Warc-unsafe-retained-assign | assigning retained object to %select{weak|unsafe_unretained}0 %select{property|variable}1 object will be released after assignment |
-Warray-bounds | array index %0 is past the end of the array (which contains %1 element%s2) |
-Warray-bounds | array index %0 is before the beginning of the array |
-Warray-bounds | 'static' has no effect on zero-length arrays |
-Warray-bounds | array argument is too small contains %0 elements, callee requires at least %1 |
-Warray-bounds-pointer-arithmetic | the pointer incremented by %0 refers past the end of the array (that contains %1 element%s2) |
-Warray-bounds-pointer-arithmetic | the pointer decremented by %0 refers before the beginning of the array |
-Wassign-enum | integer constant not in range of enumerated type %0 |
-Watomic-property-with-user-defined-accessor | writable atomic property %0 cannot pair a synthesized %select{getter|setter}1 with a user defined %select{getter|setter}2 |
-Wattributes | unknown attribute %0 ignored |
-Wauto-var-id | 'auto' deduced as 'id' in declaration of %0 |
-Wavailability | unknown platform %0 in availability macro |
-Wavailability | overriding method %select{introduced after|deprecated before|obsoleted before}0 overridden method on %1 (%2 vs. %3) |
-Wavailability | availability does not match previous declaration |
-Wavailability | overriding method cannot be unavailable on %0 when its overridden method is available |
-Wavailability | feature cannot be %select{introduced|deprecated|obsoleted}0 in %1 version %2 before it was %select{introduced|deprecated|obsoleted}3 in version %4 attribute ignored |
-Wbad-function-cast | cast from function call of type %0 to non-matching type %1 |
-Wbitfield-constant-conversion | implicit truncation from %2 to bitfield changes value from %0 to %1 |
-Wbitwise-op-parentheses | '&' within '|' |
-Wbool-conversion | "initialization of pointer of type %0 to null from a constant boolean " "expression |
-Wbridge-cast | %0 cannot bridge to %1 |
-Wbridge-cast | %0 bridges to %1, not %2 |
-Wbuiltin-requires-header | declaration of built-in function '%0' requires inclusion of the header stdio.h |
-Wbuiltin-requires-header | declaration of built-in function '%0' requires inclusion of the header setjmp.h |
-Wbuiltin-requires-header | declaration of built-in function '%0' requires inclusion of the header ucontext.h |
-Wc++-compat | %select{|empty }0%select{struct|union}1 has size 0 in C, %select{size 1|non-zero size}2 in C++ |
-Wc++11-compat | explicit instantiation cannot be 'inline' |
-Wc++11-compat | explicit instantiation of %0 must occur at global scope |
-Wc++11-compat | explicit instantiation of %0 not in a namespace enclosing %1 |
-Wc++11-compat | explicit instantiation of %q0 must occur in namespace %1 |
-Wc++11-narrowing | constant expression evaluates to %0 which cannot be narrowed to type %1 in C++11 |
-Wc++11-narrowing | type %0 cannot be narrowed to %1 in initializer list in C++11 |
-Wc++11-narrowing | non-constant-expression cannot be narrowed from type %0 to %1 in initializer list in C++11 |
-Wc++98-c++11-compat | type definition in a constexpr %select{function|constructor}0 is incompatible with C++ standards before C++1y |
-Wc++98-c++11-compat | use of this statement in a constexpr %select{function|constructor}0 is incompatible with C++ standards before C++1y |
-Wc++98-c++11-compat | init-captures.def warn_cxx11_compat_init_capture : Warning "initialized lambda captures are incompatible with C++ standards " "before C++1y |
-Wc++98-c++11-compat | variable declaration in a constexpr %select{function|constructor}0 is incompatible with C++ standards before C++1y |
-Wc++98-c++11-compat | constexpr function with no return statements is incompatible with C++ standards before C++1y |
-Wc++98-c++11-compat | multiple return statements in constexpr function is incompatible with C++ standards before C++1y |
-Wc++98-c++11-compat | variable templates are incompatible with C++ standards before C++1y |
-Wc++98-compat | substitution failure due to access control is incompatible with C++98 |
-Wc++98-compat | %select{anonymous struct|union}0 member %1 with a non-trivial %select{constructor|copy constructor|move constructor|copy assignment operator|move assignment operator|destructor}2 is incompatible with C++98 |
-Wc++98-compat | enumeration type in nested name specifier is incompatible with C++98 |
-Wc++98-compat | static data member %0 in union is incompatible with C++98 |
-Wc++98-compat | default template arguments for a function template are incompatible with C++98 |
-Wc++98-compat | scalar initialized from empty initializer list is incompatible with C++98 |
-Wc++98-compat | befriending %1 without '%select{struct|interface|union|class|enum}0' keyword is incompatible with C++98 |
-Wc++98-compat | use of null pointer as non-type template argument is incompatible with C++98 |
-Wc++98-compat | friend declaration naming a member of the declaring class is incompatible with C++98 |
-Wc++98-compat | non-class friend type %0 is incompatible with C++98 |
-Wc++98-compat | befriending enumeration type %0 is incompatible with C++98 |
-Wc++98-compat | use of non-static data member %0 in an unevaluated context is incompatible with C++98 |
-Wc++98-compat | friend function %0 would be implicitly redefined in C++98 |
-Wc++98-compat | %select{class template|class template partial|variable template|variable template partial|function template|member function|static data member|member class|member enumeration}0 specialization of %1 outside namespace %2 is incompatible with C++98 |
-Wc++98-compat | reference initialized from initializer list is incompatible with C++98 |
-Wc++98-compat | redundant parentheses surrounding address non-type template argument are incompatible with C++98 |
-Wc++98-compat | initialization of initializer_list object is incompatible with C++98 |
-Wc++98-compat | use of 'template' keyword outside of a template is incompatible with C++98 |
-Wc++98-compat | non-type template argument referring to %select{function|object}0 %1 with internal linkage is incompatible with C++98 |
-Wc++98-compat | use of 'typename' outside of a template is incompatible with C++98 |
-Wc++98-compat | passing object of trivial but non-POD type %0 through variadic %select{function|block|method|constructor}1 is incompatible with C++98 |
-Wc++98-compat | goto would jump into protected scope in C++98 |
-Wc++98-compat | constructor call from initializer list is incompatible with C++98 |
-Wc++98-compat | 'auto' type specifier is incompatible with C++98 |
-Wc++98-compat | delegating constructors are incompatible with C++98 |
-Wc++98-compat | 'constexpr' specifier is incompatible with C++98 |
-Wc++98-compat | inheriting constructors are incompatible with C++98 |
-Wc++98-compat | explicit conversion functions are incompatible with C++98</ |