Is it possible to set the return type of a selector in objective-c to be the class itself?
For example, is it possible to do something like:
+ ([self class] *) selectorName;
So that given a super class such as:
@interface MyClass : NSObject {}
+ (MyClass *) instanceOfMyClass;
@end
@implementation MyClass
+ (MyClass *) instanceOfMyClass {
return [[[[self class] alloc] init] autorelease];
}
@end
The subclass does not need to cast the return value when doing things like:
@implementation MySubClass
+ (MySubClass *) specialInstanceOfMySubClass {
MySubClass *instance = [[self class] instanceOfMyClass];
instance.special = YES;
return instance;
}
@end
In other words, im trying to expose the fact that the static method returns an instance of the class or its subclass. Otherwise, the subclass needs to be aware of information not provided in the interface.
Thanks!