Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Initialisation of immutable value'context' was never used, consider replacing assignment to '_' or removing it

Tags:

swift

In swift I declared a variable as

let context:LAContext = LAContext()

It throws a warning

"Initialisation of immutable value'context' was never used, consider replacing assignment to '_' or removing it.

like image 390
Vinayaka S Yattinahalli Avatar asked Oct 15 '15 10:10

Vinayaka S Yattinahalli


1 Answers

It's all in the error message

value...was never used

Your variable isn't being used anywhere, so Xcode tells you that you can remove it (because having unused variables is a waste of memory). Just use your variable somewhere and the error will go away (e.g. get a value from it, print it, etc).

Of course you mean to use it somewhere right? Otherwise you wouldn't have declared it. It's just that the Xcode (especially the new one, I noticed) checks for errors immediately, so these kinds of errors appear before you can really do anything about it.

Edit: I didn't imagine that almost 7 years later people would still be commenting on a post regarding a beginner-level compiler warning, but to be more specific, yes there are some cases where you might not want to keep a variable around or where you want to discard some return value, so you don't necessarily always "mean to use it somewhere". See comments for more.

like image 179
Arc676 Avatar answered Oct 10 '22 22:10

Arc676