Skip to content

Instantly share code, notes, and snippets.

@coryalder
Created July 31, 2015 21:49
Show Gist options
  • Save coryalder/1c7130dac2fa78ecf623 to your computer and use it in GitHub Desktop.
Save coryalder/1c7130dac2fa78ecf623 to your computer and use it in GitHub Desktop.
id and protocol conformance
// 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