Reputation: 3234
When you have a signature like this:
- (UIView *)fooView;
You can return any subclass of UIView
* (e.g UIScrollView
)
And when you have:
- (Class)anyClass;
You can return any class (not an instance, the class itself) but is there a way to only allow classes of a certain class or subclass? E.g in psuedo code:
- ([UIView class])bazClass;
So here it should only be able to return a class UIView
of any of its subclasses.
Upvotes: 1
Views: 644
Reputation: 17364
As specified by other users, you can't.
If your goal is to instruct other programmers about what to return from a method in your code (overriden or delegate method), you can:
.
typedef Class ClassOfKindUIView;
-(ClassOfKindUIView)class
{
return [super class];
}
This won't block anything, but it can be a "talking method", an escamotage, to make the programmers stop and think "what is this??", then cmd-click and read the docs :-)
Upvotes: 2
Reputation: 108151
What you're looking for is a sort of type bound on the return type.
Unfortunately this is not possible in Objective-C, so I'm afraid you're out of luck.
Upvotes: 0