Re: Subclasses and @property declarations
Re: Subclasses and @property declarations
- Subject: Re: Subclasses and @property declarations
- From: Graham Cox <email@hidden>
- Date: Tue, 04 Mar 2014 21:43:13 +1100
On 4 Mar 2014, at 9:20 pm, William Squires <email@hidden> wrote:
> Question: Do I have to list the @property line in CSquare.h in order for users of CSquare to be able to access the "area" property? Or is it sufficient that (because I'm overriding it, and it has the same method signature - i.e. selector) the superclass CParallelogram has already declared it?
No, you don't have to list it. It's inherited from the super class.
> 2nd Question: If I stick CParallelogram instances (well, references, really), or subclasses thereof into a collection object (NSArray, NSDictionary, etc...) and I later iterate over them, asking for their areas, will I get the correct polymorphic behavior (i.e. the selector mechanism will correctly point to the subclass instance and send the "area" message there), or do I have to pull the reference out of the collection, test and typecast it, then call for its area?
No, there is no need to do anything special. If you iterate on "area" it will invoke the -area method of each object, so it will work as you want.
@property is just syntactic sugar for standard getter and setter methods, so you can rely on method calls being used to return the property of interest.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden