[英]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! 谢谢您的帮助!
"Class" is the type you want to return “类”是您要返回的类型
@implementation MyClass
- (Class)nextPage {
return [SomeOtherClass class];
}
@end
Hope it works, ief2 希望它起作用,ief2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.