iOS Help with unused variable and NSString may not respond

ericb8272

macrumors newbie
Original poster
Apr 3, 2010
3
0
I am new to programming and to the iPhone. I am trying to recreate an app that I found in a book on iPhone programming as practice before I attempt to make an original app. This app has a slider and a label beside the slider that should change when the slider is moved. I am receiving 2 errors and a warning on 2 lines of code. Unused variable 'percentage' on one line and NSString may not respond to +stringWith and expected ] before format on another line. I'm sure this is something simple but I'm stuck and have no one to ask for help. Any help would be greatly appreciated.


Code:
// determine if customPercentSlider generated the event
		else if (sender == customPercentSlider)
		{
			// the "Custom" slider was moved
			// round the value to a whole number
			int percentage = (int)(customTipPercent * 100);
			
			//update the label with the new percentage followed by %
			customPercentLabel.text = 
				[NSString stringWithFormat:@"%i%%", percentage];
			
			// convert percentage back to float and assign to Slider's value
			float newSliderValue = newSliderValue;
			customPercentSlider.value = newSliderValue;
			
			// slider Thumb moved; update customTipPercent
			customTipPercent = newSliderValue;
		} // end else
The first error is on the line that starts int percentage. The next 2 are on the line [NSString stringWithFormat:mad:"%i%%", percentage];
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
I don't see any error in the code you posted. Try moving the two lines onto one line (although it should be ok on two lines as you showed it). The compiler seems to think there's a space or line break between stringWith and Format but there is none in the code you showed.

Code:
customPercentLabel.text = [NSString stringWithFormat:@"%i%%", percentage];
 

ericb8272

macrumors newbie
Original poster
Apr 3, 2010
3
0
Thanks for the responses. I tried your suggestion and it still did not clear the errors.

The first error is unused variable 'percentage'

Code:
int percentage = (int)(customTipPercent * 100);
The next two are expected ']' before 'Format' and 'NSString' may not respond to '+stringWith'

Code:
customPercentLabel.text = [NSString stringWithFormat:@"%i%%", percentage];
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Yes, you already said what the errors were. And as I said that compiler thinks there's a break between the 'stringWith' and the 'Format'.

Try deleting that line from your source file and typing it again.
 

ericb8272

macrumors newbie
Original poster
Apr 3, 2010
3
0
Thank you very much! This morning I deleted the lines of code and re-entered them, as you suggested. It worked and the app worked perfectly in the simulator. Again thanks.