问题描述:

I'm developing an application using swift. Today I updated my Xcode (version 7) and I get a lot of same warning.

the problem is in the for-statement

here's the code:

 let dict:NSDictionary

for dict in offers_to_show{

//do something

}

  • offers_to_show is a NSArray and it contains only NSDictionary

I get "Immutable value 'dict' was never used; consider replacing with '_' or removing it"

How can I solve it?

thank for your support,

Mirco

网友答案:

When you name the binding variable dict, you're shadowing the local variable dict (which you never use). Swift is telling you to remove the unnecessary (and confusing) let dict:NSDictionary line.

网友答案:

I get "Immutable value 'dict' was never used

That's because there are two dict variables: the constant one that you create on the first line, and the one in the for loop. As described in the docs, the index variable in a for-in loop is declared implicitly -- you don't need to declare it yourself as you're trying to do with the let dict... line, and again, that's actually a separate variable in a different scope.

You're not using the first one, so the compiler points this out. Nothing changed in your code -- the compiler just got better at finding unused code.

相关阅读:
Top