Jake
Jake

Reputation: 304

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

relatively new programmer here. Look at 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!

Upvotes: 0

Views: 98

Answers (1)

v1Axvw
v1Axvw

Reputation: 3054

"Class" is the type you want to return

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

Hope it works, ief2

Upvotes: 7

Related Questions