I am trying to override a UIStoryboard method using a category. Here is my implementation:
#import "UIStoryboard+SomeCategory.h"
#import <UIKit/UIKit.h>
@implementation UIStoryboard(SomeCategory)
-(id)instantiateInitialViewController
{
NSLog(@"SUPER CLASS: %@", [super class]); // logs "UIStoryboard"
NSLog(@"SUPER RTS : %@", [super respondsToSelector:@selector(instantiateInitialViewController)] ? @"YES" : @"NO"); // logs "YES"
return [super instantiateInitialViewController];
}
@end
when I add:
UIViewController *viewController = [super instantiateInitialViewController]
Why do I get the compiler error:
Receiver type 'NSObject' for instance message does not declare a method with selector 'instantiateViewController'
You should note that
[super class]is not the same as[self superclass]. Quoting the docs:Objective-C provides two terms that can be used within a method definition to refer to the object that performs the method—self and super.
They differ in how the compiler will search for the method implementation, and in some cases they will mean just the same.
In this case you want:
to check an object’s super class class, and you’ll need a UIStoryBoard subclass, not a category, to be able to use:
Why
[super class]doesn’t log what you expect is another subject. If you’re interested, this post What is a meta-class in Objective-C? is a good starting point.