In this code:
@synthesize username, password, sliderLabel;
-(IBAction) sliding: (id) sender;
{
UISlider *s = (UISlider*)sender;
int value = (int) s.value;
NSString *newLabel = [ [NSString alloc] initWithFormat:@"%i", value];
sliderLabel.text = newLabel;
}
I synthesize username and password and it does the getter and setters itself.
But then I create an UISlider and can do s.value….
So two questions:
1.
Am I wrong in thinking like this:
username is an UITextField – an object.
This object has variables so when we property – and – synthesize the username variable, all its(the objects) variables get setters/getters – so I can do username.text etc?
If I am wrong – then how is it?
2.
Why am I able to do s.value? It just feels wrong.
I had to synthesize username, password and sliderLabel.. but I could instantly do s.value?
1.
you can get and change all (not the read only) properties of userName (UITextFiels object) because the UITextFiels class has got setter and getter methods for all its properties
2.
when you call
s.valueyou are just calling the getter method in UISlider class…you are just calling:
[s value];(=meaning getValue)that’s why apple used synthesize when it created the UISlider class for the var/property “value”, so you can access to it with the public getter and setter methods