Last active
August 29, 2015 14:10
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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