Swift 2 unused persistent warning

I get a warning that my constant is not used:

The initialization of the immutable value "myConst" has never been used; consider replacing with assignment to '_' or deleting it

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

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

+5
source share
4 answers

You do not replace let with _ , but you replace it with a name. If the variable is not used anywhere in the code, it does not matter, so the line can be written like this:

 _ = someVal["value"] 

If you want to use it somewhere, you need a name for its link later. But when you do not use it, writing _ much easier ...

+13
source

we can use the wildcard pattern '_' for unused constant warings

+1
source

If you never use it, the compiler should not use let/var variable_name . Therefore, do not replace it _ if you want to use it later.

0
source

I think this proposal was planned for statements of โ€œif yesโ€ and the like. They will probably be removed for useless claims about future updates.

0
source

Source: https://habr.com/ru/post/1231974/


All Articles