Skip to content

Instantly share code, notes, and snippets.

@woolsweater
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woolsweater/90d5e96df0583a4d771b to your computer and use it in GitHub Desktop.
Save woolsweater/90d5e96df0583a4d771b to your computer and use it in GitHub Desktop.
Class objects in id variables will respond to selectors that are the same as instance method names.
#import <Foundation/Foundation.h>
@interface Deleg : NSObject
+ (void)delegatorDidSomething;
- (void)delegatorDidSomething;
@end
@implementation Deleg
+ (void)delegatorDidSomething
{
NSLog(@"Classy");
}
- (void)delegatorDidSomething
{
NSLog(@"Instantaneous");
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
id c = [Deleg class];
id i = [Deleg new];
NSCAssert([c respondsToSelector:@selector(delegatorDidSomething)],
@"Class object does not respond");
[c delegatorDidSomething];
NSCAssert([i respondsToSelector:@selector(delegatorDidSomething)],
@"Instance does not respond");
[i delegatorDidSomething];
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment