Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 2 unused constant warning

I am getting a warning saying my constant is unused:

Initialization of immutable value 'myConst' was never used; consider replacing with assignment to '_' or removing it

if someVal["value"] != nil {
    let myConst = someVal["value"]
}

So what will renaming let myConst = someVal["value"] into _ myConst = someVal["value"] do/mean?

like image 694
user2722667 Avatar asked Sep 21 '15 21:09

user2722667


2 Answers

You're not replacing let with _, but you're replacing the variable name with it. If the variable isn't used anywhere in the code it's irrelevant so the line can be written like:

_ = someVal["value"]

If you want to use it somewhere you need a name for it to reference it later on. But when you don't use it writing _ is a lot easier ...

like image 62
Kristijan Delivuk Avatar answered Oct 18 '22 07:10

Kristijan Delivuk


we can use Wildcard Pattern ' _ ' for unused constant warings

like image 35
Narendra G Avatar answered Oct 18 '22 05:10

Narendra G