Created
July 31, 2015 21:49
-
-
Save coryalder/1c7130dac2fa78ecf623 to your computer and use it in GitHub Desktop.
id and protocol conformance
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
// when specify id as the type, you can use NSObject methods. | |
// when you specify as a custom protocol, you cannot. | |
// UNLESS you say that your custom protocol includes <NSObject> | |
#import <Foundation/Foundation.h> | |
@protocol CustomProtocol // <NSObject> // uncommenting <NSObject> fixes the issue | |
@end | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
// insert code here... | |
NSLog(@"Hello, World!"); | |
id thing1; | |
if ([thing1 isKindOfClass:[NSString class]]) { | |
// works fine | |
} | |
id <CustomProtocol> thing2; | |
if ([thing2 isKindOfClass:[NSString class]]) { | |
// does not compile | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment