Question

If subclass in objective-c wants to override a super class's method, does it have to match the return type too?

Was it helpful?

Solution

Yes, it must have the same selector.

update:

IIRC the arguments also needs to have the same types.

update:

It seems that all methods of the same selector needs to have equivalent types across all classes when linking dynamically, not so with static linking: linky

OTHER TIPS

Yes, It be same,

But one thing to be noted is you need to pass the super-class of return types.

Eg:

-(UIScrollview)method:(id)argument;

you can return UIview as well. (simply saying super class of return types).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top