升级xCode版本后 block 出现大量的警告,通过方法一和方法二可以消除大量的block相关的警告,同时下面也有一些消除第三方相关的警告。

方法一
Block implicitly retains ‘self’; explicitly mention ‘self’ to indicate this…的警告

在Build Setting里面搜索Implicit retain of ‘self’ within blocks里面从YES设置为NO即可

方法二
This block declaration is not a prototype

Build Setting -> 搜索 Strict Prototypes 设置成NO。

其他警告:

记录接手的项目优化遇到的警告信息和处理方式

1、清除一些需要忽略的警告
Targets -> Build Settings (选择All,搜索custom)-> Apple Clang - Custom Compiler Flags -> Other Warning Flags.

填入要忽略的警告类型
右键警告点击 Reveal in Log 查看报警类型
例如: -Wdocumentation,填入内容为 -Wno-documentation,在W后面添加"no-"。

参考:忽略xcode的警告方法

2、Pod中的第三方库指定编译目标不在Xcode范围内
The iOS deployment target ‘IPHONEOS_DEPLOYMENT_TARGET’ is set to 6.0, but the range of supported deployment target versions is 8.0 to 13.6.99.

将下述内容添加在PodFile的最下方,重新执行Pod install。

post_install do |installer|installer.pods_project.targets.each do |target|target.build_configurations.each do |config|config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '8.0'endend
end

参考:iOS小记–warning: The iOS deployment target is set to 6.0, but the range XXX

3、Pod第三方库的警告
在Podfile中加入 “inhibit_all_warnings!”

source 'https://github.com/CocoaPods/Specs.git'platform :ios, '9.0'
inhibit_all_warnings!target "xxxx" do

4、支付宝SDK的警告
(arm64) /Users/intfre/workspace/other/ios-msdk-git/AlipaySDK4Standard/AlipaySDK/Library/UTDID.framework/UTDID(AidManager.o) unable to open object file: No such file or directory

Go to Build Settings -> Build Options -> Debug Information Format

Change the Debug setting from “DWARF with dSYM File” to “DWARF”

Leave the Release setting at “DWARF with dSYM File”

参考:集成支付宝报警告

5、Pod中AFNetworking警告
MobileCoreServices has been renamed. Use CoreServices instead.

提示已经很明确了,按提示操作。

6、Launch images警告
Launch images are deprecated in iOS 13.0. Use a launch storyboard or XIB instead.

Assets里面移除Launch images,使用LaunchScreen;
Build Setting里搜索LaunchImages -> Asset Catalog Launch Image Set Name -> 移除LaunchImages

7、block的参数没有设置也没有写void报警告
This block declaration is not a prototype

Build Setting -> 搜索 Strict Prototypes 设置成NO。
block不设置参数的话,可以传任意个任意类型参数,设置成void就真的不能传参数了。有时候确实需要设计成传任意参数的,消除警告目前没有发现有什么不妥的地方,旧项目999+的错误,直接不提示好了。

8、block里面调用参数没有用self指针报警告
Block implicitly retains ‘self’; explicitly mention ‘self’ to indicate this is intended behavior

Build Setting -> 搜索 Implicit retain of ‘self’ within blocks 设置成NO。
Block里面避免循环引用,最好用weakself调用参数,写代码时养成习惯,顺手写上肯定不会出错。旧项目警告太多,运行稳定,就直接消除警告吧。

参考:xcode编译后警告的解决方法

9、误用逗号标点符号
possible misuse of comma operator here [-Wcomma]
free(coordinates), coordinates = NULL;

改掉。

10、 传参类型问题
Incompatible pointer types sending ‘NSArray *’ to parameter of type ‘NSMutableArray * _Nonnull’

改掉,方法里传NSArray就好了,因为NSMutableArray继承自NSArray,方法里面需要用可变对象的话,mutableCopy下。

11、使用YYCache缓存对象,实现了NSCoding的协议方法,但是没有在@interface 后面写报警告
Sending ‘xxx *’ to parameter of incompatible type ‘id _Nullable’

加上。

12、没有实现delegate里的方法
Class ‘xxxViewController’ does not conform to protocol ‘xxxDelegate’

实现对应方法,或者不需要实现的话在delegate非必须实现的方法上面添加@optional。

13、没有在interface后面声明UIGestureRecognizerDelegate协议
Assigning to ‘id _Nullable’ from incompatible type ‘xxxViewController *const __strong’

加上。

14、实现弃用的方法
Implementing deprecated method

看方法的适用范围,和自己项目支持的最低版本,决定删除还是区分版本处理。

15、performSelector调用警告
performSelector may cause a leak because its selector is unknown

看代码,Selector是个参数,编译器无法确定这个方法存在,所以报警告

[_delegate performSelector:_shareClick withObject:[NSNumber numberWithInteger:button.tag - 70]];
1
暂时消除警告,当然要自己确定这个方法存在,否则,自己试一下吧。

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[_delegate performSelector:_shareClick withObject:[NSNumber numberWithInteger:button.tag - 70]];
#pragma clang diagnostic pop

参考:爆栈热门 iOS 问题

16、#import结尾加了分号
Extra tokens at end of #import directive

这个。。。删了分号,不知道怎么会加分号,还不止一个类,这是某位仁兄要留下自己的标记吗。还是我无知,有什么不知道的高级含义。

17、注释里的警告
Documentation Issue Group

注释里有个 报警告
HTML tag ‘a’ requires an end tag

使用@param options说明方法里的参数但是方法里没有这个参数报警告
Parameter ‘options’ not found in the function declaration
这个字段后面没有说明内容报警告
Empty paragraph passed to ‘@param’ command

在 Build Settings 搜索 Other Warning Flags 填入 -Wno-documentation。
警告类型为-Wdocumentation,W后面加上no-,表示不显示这种类型警告。
我们自己在写代码写注释时最好写清楚各个字段含义,修改时注释内容一并改掉

18、字符串类型转换警告
Format String Issue Group

代码中int型的值转字符串使用了@"%zd", i,zd我也是第一次见到,参考这篇文章吧
printf中的format格式 %zd

int型直接用%d就好了。

给一个参数传了空值报警告
Null passed to a callee that requires a non-null argument

@property (nonatomic, strong) NSDictionary * dicData;
self.dicData = nil;

加个可为空的标识可消除警告。

@property (nonatomic, strong) NSDictionary *_Nullable dicData;

原文链接:https://blog.csdn.net/u011248221/article/details/107937408

消除警告(升级后block警告)相关推荐

  1. Xcode 升级后,常常遇到的遇到的警告、错误,解决方法

    Xcode 升级后,常常遇到的遇到的警告.错误,解决方法 参考文章: (1)Xcode 升级后,常常遇到的遇到的警告.错误,解决方法 (2)https://www.cnblogs.com/cooka/ ...

  2. Dell(戴尔)笔记本加装内存条后出现警告:“Warning Message : Alter!The amount of system memory has changed”

    Dell(戴尔)笔记本加装内存条后出现警告:"Warning Message : Alter!The amount of system memory has changed",点击 ...

  3. 消除Xcode iOS项目的警告

    消除Xcode iOS项目的警告 作者  犯傻小二  关注 2016.03.10 15:22*  字数 8287  阅读 3839 评论 0 喜欢 7 如果你有强迫症,看到项目中那么多警告肯定特别心烦 ...

  4. 奥兹的 “末日 “备忘录警告微软后PC时代的到来

    奥兹的 "末日 "备忘录警告微软后PC时代的到来 Ozzie's 'doomsday' memo warns Microsoft of post-PC days 一位行业分析师今天 ...

  5. 数据库升级后,准备使用原有数据文件启动数据库

    因听到以前同事说到11.2.1版本在进行子查询时,速度有时会莫名的慢下来.正好有时间,也是测试服务器, 那就把数据库升级到11.2.3吧.原计划是升级后可以直接使用数据库的相关文件就能启动数据库. 但 ...

  6. mac 10.13 配置 php,MacOS10.13.6 升级后 PHP7.3配置

    MacOS10.13.6 升级后 PHP7.3配置 几乎每次Mac系统升级后,PHP都要重新配置,最近升级了MacOS到10.13.6: PHP通过brew update php升级到7.3: 随后要 ...

  7. [Remoting]dotNet Framework升级后Remoting信道使用的安全问题

    [Remoting]dotNet Framework升级后Remoting信道使用的安全问题<?xml:namespace prefix = o ns = "urn:schemas-m ...

  8. nc升级后java_用友NC系统使用过程中常见问题和解决方法

    用友NC系统使用过程中常见问题和解决方法: 1.无法安装客户端插件,不能进入NC系统登陆界面 问题现象 现象1:可以打开web界面,但无法进入登陆界面,一直停留在右图所示界面. 现象2:系统提示安全警 ...

  9. excel隐私警告_Excel隐藏数据警告

    excel隐私警告 Excel隐藏数据警告 (Excel Hidden Data Warning) Have you seen the articles that blame Excel for al ...

最新文章

  1. EnterpriseDB Migration 迁移工具使用测试(2)
  2. linux查看python环境变量_Linux中的Python环境变量
  3. Java SE 重点知识笔记
  4. 在nginx.conf中配置https
  5. CodeForces - 1454F Array Partition(线段树+二分)
  6. LeetCode 1952. 三除数
  7. 福特在迈阿密开始探索自动驾驶商业模式:先送比萨试试
  8. bzoj 1798 5039: [Jsoi2014]序列维护(线段树)
  9. 2017-2018-2 1723《程序设计与数据结构》第三周作业 实验一 总结
  10. EVE上传Dynamips、IOL和QEMU镜像
  11. 离散数学笔记整理(个人向)
  12. 关于antd中嵌套表格expandable属性如何设置为可变化的
  13. ROS编译ORB-SLAM2或其各种变种的算法遇到的编译问题
  14. 域名被微信屏蔽如何解决
  15. useragent怎么获取
  16. 大吉大利今晚吃鸡——枪械篇
  17. 计算机专业的英文简历范文带翻译,计算机软件专业英文简历范文 英文简历范文带翻译...
  18. 【数学问题】利用python求解表达式
  19. 抖音运营干货:3个月4抖音号狂吸400W+粉丝
  20. c++ 反射_实现光时域反射仪中的应用原理基于飞凌FETA40i-C核心板

热门文章

  1. 成都java就业前景好不好
  2. 启发式教学的二十种实用方式教学与教学方法的关系
  3. SAP FIORI专题之四:使用fiori element构建over page
  4. 串口通信USART_ReceiveData(USARTx)接收串口 数据类型
  5. c# opencv车牌识别_opencv +数字识别
  6. gcc : 无法将“gcc”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
  7. IDEA报:mvn : 无法将“mvn”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次....问题
  8. 斐讯K2无法运行KCPTUN占用CPU特别高的问题
  9. Excel中的数据有效性
  10. 《系统分析与设计》团队第一次作业