警告提示收集


其他人的:

https://www.jianshu.com/p/a1aa0df5aa3c
Enum values with underlying type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead

或 Values of type ‘NSInteger’ should not be used as format arguments; add an explicit cast to ‘long’ instead
FIX: Replace
'%d, animated = %d", __FUNCTION__, ' with '%ld, animated = %d", __FUNCTION__, (long)'

苹果app支持arm64以后会有一个问题:NSInteger变成64位了,和原来的int (%d)不匹配,所以会报warning,

NSInteger的定义(如下),在64位系统中NSInteger是long, 32位中是int。所以"%d"在64位上当然是不足以够位长,这里修改为"%ld"合情合理。

#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
  typedef long NSInteger;
  typedef unsigned long NSUInteger;
#else
  typedef int NSInteger;
  typedef unsigned int NSUInteger;
#endif
 

其它方式:强制转换    [NSString stringWithFormat:@"%d"(int)number];

     [NSString stringWithFormat:@“%@", @(number)];

Unused variable 未使用的变量

https://blog.csdn.net/nwpu053883/article/details/103351032

https://stackoverflow.com/questions/7090998/portable-unused-parameter-macro-used-on-function-signature-for-c-and-c
指针类型不兼容
Incompatible pointer types assigning to 'AAA *' from 'BBB *'  

 Incompatible pointer types returning 'AAA' from a function with result type 'BBB'

 
Duplicate key in dictionary literal 在字典字面量中重复键

Multiple declarations of method 'xxx:' found and ignored 方法'xxx:'的多个声明被发现和忽略
Null passed to a callee that requires a non-null argument

此警告就是某属性说好的不能为空,你又在某地方写了 nil 所以冲突了

在宏NS_ASSUME_NONNULL_BEGIN和NS_ASSUME_NONNULL_END 包住,全部具备nonnull

 出现的原因是由于Xcode10以后,系统对新建类默认加上NS_ASSUME_NONNULL_BEGINNS_ASSUME_NONNULL_END这样的一对宏,但是我们对某些对象置nil而导致的。 知道了原因先来看下介这对宏的作用:我们都知道Swift将对象分为optional(?)non-optional(!)的,但是OC却没有这一特性。为了解决Swift和OC混编时的对象问题,Xcode6.3时苹果推出了这样的一对宏。这对宏的主要作用是将在这两个宏之间的代码,所有简单指针对象都会被假定为nonnull,因此我们只需要去指定那些nullable的指针。 因为所有对象都被假定为nonnull了,而这时将某一对象或参数置nil,所以编译器会报此警告。

解决的方法也很简单,我们只要在申明对象时对需要nil的对象或参数,加上nullable关键字即可。

从这个警告可以发现,苹果一直想让OC往Swift的方向发展兼容,从Xcode6.3的提出,到Xcode10的默认添加都能看出。


  is deprecated: 已弃用

 'openURL:' is deprecated: first deprecated in iOS 10.0
 Replace 'openURL' with 'openURL:options:completionHandler:'

 'automaticallyAdjustsScrollViewInsets' is deprecated: first deprecated in iOS 11.0 - Use UIScrollView's contentInsetAdjustmentBehavior instead

 已弃用的方法与替换方法

Undeclared selector 'aaa'

未申报的选择器 aaa

Method definition for 'aaa:' not found

未找到'aaa '的方法定义

Empty paragraph passed to '@param' command

其实原因就是注释不合苹果的要求,所以,出现了新的警告,要么修改这些警告为要求的格式,要么全局隐藏这些警告。但是因为引入了第三方友盟,所以,不大可能去直接修改这些文件。要么更新友盟SDK到最新版本(友盟官方未必已经解决),要么就全局隐藏。

如何全局消除这些警告呢?

如下:在Other Warning Flags 里面添加-Wno-documentation

#pragma 处理警告 https://www.jianshu.com/p/3c7a4feaee16 

方法注释的正确写法是什么?

Parameter 'date' not found in the function declaration

Empty paragraph passed to '@param' command

This block declaration is not a prototype

typedef void(^transactionBlock)(); 

()里没有填写void,在xcode9中会提示一个警告

typedef void(^transactionBlock)(void);

但是这样,很多第三方要改,涉及的面太大了,目前可能不太适合,虽然这个是趋势.

或者,如果只是很少的地方,也可以使用彻底的暂时解决所有这种警告的方式

在工程的设置中

strict-prototypes 设置为NO,则这些警告就消失了

Block implicitly retains 'self'; explicitly mention 'self' to indicate this..

其中的意思是block中使用了self的实例变量 _xxx ,因此block会隐式的retain住self。Xcode认为这可能会给开发者造成困惑,或者因此而因袭循环引用,所以警告我们要显示的在block中使用self,以达到block显示retain住self的目的。
  • 方案一:

  按照Xcode提示,改成self->_xxx

  • 方案二:

   Building Settings->CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF 设置为NO

This old-style function definition is not preceded by a prototype

即使函数括号内没有任何参数,也要加一个void类型,来避免这种warning
iOS 开发去除 CocoaPods 警告(Fix Xcode Warning)

https://blog.csdn.net/hongfengkt/article/details/82626147?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-82626147-blog-81701169.pc_relevant_paycolumn_v3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-82626147-blog-81701169.pc_relevant_paycolumn_v3&utm_relevant_index=2

因为从 Xcode8.0 开始,引入了文档注释的警告 。
Implicit conversion loses integer precision: 'UIInterfaceOrientation' (aka 'enum UIInterfaceOrientation') to 'int'

出现Implicit conversion loses integer precision: 'NSUInteger' (aka 'unsigned long') to 'int意思是NSUinteger隐式转换int会丢失精度,会报这个??但是程序可以正常运行,要消掉这个警告需要手动转换比如:
(int)array.count

或者在build phases 对应文件添加  -Wno-shorten-64-to-32
stringByAddingPercentEscapesUsingEncoding 警告

这个方法从2.0支持到 9.0后不支持了,建议用
stringByAddingPercentEncodingWithAllowedCharacters 替换

例:

NSString *hStr = @"你好啊";
NSString *hString = [hStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

替换后: 

NSString *hStr =@"你好啊";
NSString *hString = [hStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

Assigning to 'id _Nullable' from incompatible type 'xxxVC *' 

提示分配给"UITextFieldDelegate"是类型有误的!从不兼容类型“
xxxVC*”分配到“id<cccDelegate> _Nullable”

基本上是由两种情况造成的:


1、没有遵守协议(基本上都是这种情况造成的)


解决办法:遵守这个协议



2、strong 类型不兼容


解决办法:将 strong 改为 weak 

 
This file is set to build for a version older than the deployment target. Functionality may be limited.
将此文件设置为针对比部署目标更老的版本进行构建。功能可能有限。

解决方法:

选中xib 的文件 , 在 show the file inspector 选项栏中的 Interface Builder Document 下的 Builds for 选中  Project Deployment Target

Implicit conversion from enumeration type 'enum CFNumberFormatterStyle' to different enumeration type 'NSNumberFormatterStyle' (aka 'enum NSNumberFormatterStyle')

隐式转换问题
CFNumberFormatterStyle 改用 NSNumberFormatterDecimalStyle 
Method override for the designated initializer of the superclass '-init' not found
未找到超类'-init'的指定初始化式的方法重写

重写init方法 或 禁用init方法
参考: https://www.jianshu.com/p/c8f6aafb0117
iOS