I am having a bit of trouble understanding this piece of code. It is from a book I am reading but I feel like the guy is just telling me to type stuff without explaining it in much depth.
- (IBAction)sliderChanged:(id)sender
{
UISlider *slider = (UISlider *)sender; //set slidervar as active slider
int progressAsInt = (int)(slider.value + 0.5f);
NSString newText = [[NSString alloc] initWithFormat:@"%d",progressAsInt];
sliderLabel.text = newText;
[newText release];
}
the issue is with the first line
UISlider *slider = (UISlider *)sender; //set slidervar as active slider
I do not understand what typecasting is, which is what the guy says in the book. "avoids needing to typecast sender everytime we use it"
I also do not understand what/why the second line has int
in brackets. I am used to having code like
int progressAsInt = 56