开发者

Is it possible to return a class (but not an instance of a class) in Objective-C?

开发者 https://www.devze.com 2023-01-11 10:49 出处:网络
relatively new programmer here. Look a开发者_JS百科t the two classes defined below. I\'d like to be able to call the following:

relatively new programmer here. Look a开发者_JS百科t the two classes defined below. I'd like to be able to call the following:

[instanceOfSecondClass transitionToPage: [instanceOfFirstClass nextPage]];

However, that doesn't seem to work (because I'm trying to return a class, not an instance of a class.)

@implementation FirstClass
- (id)nextPage {
    return SomeOtherClass;
}
@end


@implementation SecondClass
- (void)transitionToPage:(id)someOtherClass {
    currentPageViewController = [[mySomeOtherClass alloc] init];
    ...
}
@end

Is there any way to accomplish what I am trying to do here?

Sometimes things that make sense to me totally don't make sense in the real world :).

Thanks for the help!


"Class" is the type you want to return

@implementation MyClass
- (Class)nextPage {
     return [SomeOtherClass class];
}
@end

Hope it works, ief2

0

精彩评论

暂无评论...
验证码 换一张
取 消