Swift 提示:Initialization of variable was never used consider replacing with assignment to _ or removing it

Swift 提示:Initialization of variable was never used consider replacing with assignment to _ or removing it

的原因:

var //代表变量,变量的值可以改变

let//代表常量类型不可改变

 var ceshi:Double = 10//假如声明的变量没有改变的话Swift也会提示将其改为let,而且在下面的代码中没有用到该变量Swift就会提示将let改为下划线,因为下划线代表忽略该变量,就相当于OC中提示并没有用该属性或者变量一样,估计没用到的变量一般人也不会写,只是给刚入门的说一下并不是你写错了或者Xcode有问题,只是Swift提示很细。可以直接删掉或者在下面给ceshi赋一个新值,在print一下就可以了。

 

 

 

 

原文地址:https://www.cnblogs.com/BK-12345/p/5904919.html