Question

resultLabel is a UILabel. So why does

 resultLabel.Text= @"";

not give an error? It should be resultLabel.text.

Thanks for any insights.

Was it helpful?

Solution

The default setter function for a property foo is setFoo:, with the first letter capitalized. Therefore both lines

resultLabel.text = @"";
resultLabel.Text = @"";

generate the same code

[resultLabel setText:@""];

This works only with the setter function, not with the getter:

NSString *x = self.text; // --> x = [self text]
NSString *x = self.Text; // --> x = [self Text]

As a consequence, you cannot have two read-write properties that differ only in the case of the first letter, this will generate a compiler error:

@property (nonatomic, strong) NSString *text;
@property (nonatomic, strong) NSString *Text;

self.text = @"foo";
// error: synthesized properties 'text' and 'Text' both claim setter 'setText:'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top