-1

When I put your flashlight dimmer coding into my app, I get this error "local declaration 'slider' hides instance variable"

Here is the code:

UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(20.0f, 20.0f, 280.0f, 40.0f)];
slider.maximumValue = 1.0f;
slider.minimumValue = 0.0f;
[slider setContinuous:YES];
[slider addTarget:self action:@selector(sliderDidChange:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:slider];
Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67
  • 4
    Please don't make another flashlight app! – woz Apr 02 '13 at 18:07
  • Let him earn some $$$$ tooo – Anoop Vaidya Apr 02 '13 at 18:09
  • possible duplicate of [Local declaration 'theslider' hides instance variable](http://stackoverflow.com/questions/15672821/local-declaration-theslider-hides-instance-variable) – jscs Apr 03 '13 at 19:21
  • rename your _local_ variable (to e.g. `slider1`) and your problem will be resolved; or use the global `slider` property instead of creating a new _local_ variable. – holex Jan 15 '16 at 10:02

3 Answers3

0

The error means there is a variable named slider somewhere in your app that is already declared. If you simply rename your variable, the error should go away.

And for Steve's sake, please don't make another flashlight app!

woz
  • 10,888
  • 3
  • 34
  • 64
0

"local declaration 'slider' hides instance variable"

This is straight forward. You need to change either of the name,

Preferably change local slider to someother name as:

UISlider *localSlider = [[UISlider alloc] initWithFrame:CGRectMake(20.0f, 20.0f, 280.0f, 40.0f)];
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(20.0f, 20.0f, 280.0f, 40.0f)];
localSlider .maximumValue = 1.0f;
localSlider .minimumValue = 0.0f;
[localSlider setContinuous:YES];
[localSlider addTarget:self action:@selector(sliderDidChange:) forControlEvents:UIControlEventValueChanged];
[self.view localSlider];
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
0

You have declared your local variable 'slider' with the same name as a previously declared instance variable. You need to either change the name of the instance variable, or the local variable, and all will be well.

codeqi
  • 753
  • 1
  • 6
  • 14