I have a function in which I hope to return different type
-(UIButton *)returnObject1 ;
{
//dosomething
return aUIButton;
}
-(UIView *)returnObject2 ;
{
//dosomething
return aUIView;
}
I hope to merge the two function to one and return different NSObject(UIButton,UIView)
Is it possible?
Welcome any comment
Just don’t declare a return type. Change it to this instead:
However…
UIButtonis a subclass ofUIView, which means you can do this instead:Note that, in objective-c, the return type of a method is completely irrelevant while the code is being executed. The entire purpose is to inform the compiler what your code expects, so that it can avoid crashes. So, specifying a return type is a good idea when possible, but is not necessary.