Variable 'xxx' was never mutated, consider changing to 'let'
来源:互联网 发布:剑雨逍遥手游进阶数据 编辑:程序博客网 时间:2024/06/17 02:00
var emptyArray = [String]()
var emptyDictionary = [String :String]()
print("the empty array is \n ", emptyArray, emptyDictionary)
解释如下:
They talked about this in the WWDC videos and the release notes.
It has always been the case that you get much, much better performance (faster speed, smaller space) if you uselet
instead of var
whenever you can. This tells the compiler that this thing is aconstant, not a variable, and that fact allows the compiler to optimize all kinds of things away.
But the compiler can't do that unless you do use let
whenever you can. It won't change avar
to a let
for you.
Therefore, in Swift 2, the compiler does a smarter analysis at build time and warns you if you are usingvar
where you could have used let
. Eventually this feature will work properly, at which point you should take the compiler's advice!
如果变量本事就是不可变的
那么尽量从var改为let
这样Swift的编译器可以对let进行优化,从而获得更好的性能
再去按照要求去改为:
let emptyArray = [String]()let emptyDictionary = [String :String]()
print("the empty array is \n ", emptyArray, emptyDictionary)
打印结果为:the empty array is [] [:]
- Variable 'xxx' was never mutated, consider changing to 'let'
- Initialization of variable was never used; consider replacing with assignment to ‘_’ or removing it
- warning #179-D:variable "XXX" was declared but never referenced
- IAR variable "l" was set but never used 错误分析
- warning: #550-D: variable "key" was set but never used
- stack around the variable "xxx"was corrupted.
- This function or variable may be unsafe Consider using xxx instead
- was mutated while being enumerated.
- was mutated while being enumerated
- was mutated while being enumerated.
- was mutated while being enumerated
- OpenCV - Stack around the variable 'XXX' was corrupted.
- Analyze提示:Value stored to "xxx"is never read
- IAR编译器一个警告信息-Warning[Pe550]: variable "变量" was set but never used
- 20140627-IAR平台中Warning[Pe550]: variable "xxxx" was set but never used的问题
- [realview] warning: #550-D: variable "d" was set but never used
- 【Keil】warning: #550-D: variable "activeTaskID" was set but never used
- error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To di
- 巴蜀 1738
- 单应性矩阵及其SVD求解
- Mybatis3.x与Spring4.x整合+代码自动生成
- 包装类型,演示Integer
- js 获取元素宽度的几种方法
- Variable 'xxx' was never mutated, consider changing to 'let'
- PAT 1075. PAT Judge (25)(pat排名)(待修改)
- C#直接使用DllImport外部Dll的方法
- Expression Add Operators
- 配置svn的实时双备
- LeetCode 382. Linked List Random Node 解题报告
- 【Android】Service+Seek Bar实现后台音乐播放器小呆萌
- android安全问题——浅谈
- Lua 标准库 - 输入输出处理(input and output facilities)