Hi,
In Objective-C, is it possible to override a property and have it return a
different type to the base class?
I have a base class with the following property defined:
@property (nonatomic,retain)ClassA* propA;
and the following getter:
-(ClassA*) propA
Hi Dave,
For myClassA, you will always have to cast the return value to myClassB
if you know that’s what will be returned. For a great blog post on the subject,
I give you Mike Ash:
https://mikeash.com/pyblog/friday-qa-2015-11-20-covariance-and-contravariance.html
Jeff Kelley
slaunch
Method return types are covariant though, yes? So you should always be able
to return a more-derived type from a method that is declared to return a
less-derived type. If I read your example right, ClassA is "Animal" and
ClassB is "Cat" (in covariance-blog-post lingo). So that is legal, unless
I'm
Hello there,
I have certain identifiers which must be read correctly in my program. In
Voiceover, they don’t read correctly so I’d like to make a dictionary which
Voiceover actually uses during the run of my program. Is this something that
is supported or is this something I’ll need to make a
> On Jan 4, 2016, at 8:24 AM, Dave wrote:
>
> myClassB = myClassA.propA;//Warning on this line saying
> return type is not ClassB
You have to declare the override in the subclass’s @interface, with the
modified return type. Otherwise callers have no idea that your override