initialization of immutable value URL was never used
Means that you didn't use the variable anywhere, so its throwing a warning. But looking at the screenshot, you have declared URL
as a var
and used it in data
which is another var.
So there should be two warnings now. URL
is declared as a var
but never mutated and data
variable was never used.
To satisfy, use let URL ...
since you are not mutating it. and do away with data
as this is a async block/closure and you can access data
from the completion block.
Note:
You should use let
when you are not modifying it later and you should use var
when you want to modify the object. Consider array :
let immutableArray:[String] = ["foo", "bar"]
var mutableArray:[String] = ["hello"]
mutableArray.append("World") // Is valid since its a var
immutableArray.append("abc") // Not valid, infact auto complete does not even show append methods