Can Objective C properties have parameters when accessing them?
For exam开发者_JAVA技巧ple, I've seen self.someProperty
, but I have never seen self.someProperty(someParameter)
.
This is a little bit unclear.
Say I have a property pinImage
-- well, I think it'd be cool to do something like:
self.image(@"SomeImage.png");
However, that's just not possible, is it?
A property in Objective-C is always in the form of theObject.property
. It never has parameters.
I am aware that @property
means you create the setProperty
and property
methods. That means the setProperty
will ALWAYS have one parameter and the self.property
will always have no parameters.
I am just trying to make sure.
You need to understand what a property actually is. Suppose you declare a property like this:
@property(nonatomic,retain)IBOutlet UIButton *someLabel;
When you synthesize it (@synthesize someLabel;
), you're actually making a method, though it's hidden, that looks something like this:
-(void)setSomeLabel:(UILabel *)aSomeLabel {
if (someLabel != aSomeLabel)
{
[someLabel release];
someLabel = aSomeLabel;
[someLabel retain];
}
}
So yes, there is a parameter, but it's hidden.
精彩评论