Swift 3.0 出现 Result of all to 'XX' is unused 警告 解决
来源:互联网 发布:淘宝一阳指是什么 编辑:程序博客网 时间:2024/05/22 12:45
近期楼主为了继续熟悉Swift,很多的Demo也是努力的让自己使用Swift编写 ,不过在使用SnapKit的时候,总会冒出很多的警告,仔细一看,警告的原因几乎就是同一个,如下图:
当然,警告对于大家来说已经非常熟悉了,并且很多朋友似乎也已经习惯无视警告了,但是对于楼主这个稍微有强迫症的人来讲 (为什么说是稍微有,其实楼主只是不喜欢自己写的代码存在很多的警告,不然就要动手改动别人的东西啦o(>﹏<)o,不过还非常的感谢这个强迫症能让我主动去看一些东西,希望大家可会有这种”强迫症”哇)真的是太崩溃了,特别是一个文件全屏的警告。
转回正题,不难看出原因就是:提示我们,这个方法存在返回结果,但是我们没有使用它。可往往很多的方法返回值我们是不需要用的,特别是链式编程(函数式编程)。
这里有两种解决办法:
1、第一种:我们使用一个通配符来接收参数,如下:
这种比较适合当我们调用一些封闭的库或者比较复杂的库,我们不能或者不敢轻易的去变动源码。
2、第二种:使用@discardableResult关键词
用它修饰有返回值的方法,表示我们可以无视它的返回值,比如楼主找到了SnapKit中的那几种方法,修改如下:
这个时候原来存在满屏警告的地方就恢复正常啦,所以如果是我们尝试响应式编程或者其他不太需要返回值的方法的时候,不要忘记用@discardableResult修饰一下
0 0
- Swift 3.0 出现 Result of all to 'XX' is unused 警告 解决
- Swift Result of call to ‘XXX’ is unused
- Swift3.0 Result of call to 'XXX' is unused
- Swift3 - Result of call '***' is unused
- keil for stm32中出现的警告" integer operation result is out of ran"
- Xcode 8, Swift 3: “Expression of type UIViewController? is unused” warning
- Xcode 8 / Swift 3: “Expression of type UIViewController? is unused” warning
- Swift: 消除警告-Scene is unreachable due to lack of entry points and does not have an identifier for
- "Expression of type "UIViewController?" is unused".
- iOS中使用storyboard时出现警告Unsupported Configuration: Scene is unreachable due to lack of entry points and
- XCode8.0下面出现的警告——xx is missing from working copy的解决办法
- Git学习——使用push命令,出现The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.警告
- IOS警告:Property access result unused - getters should not be used for side effects
- 使用Storyboard时出现以下警告:Scene is unreachable due to lack of entry points and does not have an identifier
- Swift Compiler Error Cannot assign to the result of this expression
- Swift开发教程--Unused variable 'fileName'问题的解决
- 解决Xcode删除文件或更改文件路径后 missing file 警告: “xx”is missing from working copy
- springboot警告:ApplicationContext is unlikely to start due to a @ComponentScan of the default package
- matplotlib数据可视化入门-python
- c++读写文件
- SQL之AUTO INCREMENT 字段
- STM32值系统时钟初始化程序设计
- Java 动态加载jar和class文件
- Swift 3.0 出现 Result of all to 'XX' is unused 警告 解决
- Ubuntu和Windows远程连接windows服务器
- 抢小米手环脚本
- springmvc表单上传
- opencv 随机数
- 希尔排序
- 线性表数据结构解读(五)哈希表结构-HashMap
- 定义和声明
- FFmpeg学习4:音频格式转换