问题
resultLabel
is a UILabel
. So why does
resultLabel.Text= @"";
not give an error? It should be resultLabel.text
.
Thanks for any insights.
回答1:
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:'
来源:https://stackoverflow.com/questions/15410905/why-is-capitalized-property-name-not-giving-an-error-in-objective-c-uitouch