开发者

Can Objective C properties have parameters when accessing them?

开发者 https://www.devze.com 2023-03-12 09:17 出处:网络
For exam开发者_JAVA技巧ple, I\'ve seen self.someProperty, but I have never seen self.someProperty(someParameter).

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号