Created
August 28, 2011 18:20
-
-
Save chrisdevereux/1177004 to your computer and use it in GitHub Desktop.
Using protocols to avoid method signature mismatches on class methods
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 <Cocoa/Cocoa.h> | |
@protocol IdMethod | |
+ (id) method; | |
@end | |
@interface IdClass : NSObject <IdMethod> | |
@end | |
@implementation IdClass | |
+ (id) method | |
{ | |
return @"hello!!"; | |
} | |
@end | |
@protocol StructMethod | |
+ (NSRect) method; | |
@end | |
@interface StructClass : NSObject <StructMethod> | |
@end | |
@implementation StructClass | |
+ (NSRect) method | |
{ | |
return CGRectMake(5,5,5,5); | |
} | |
@end | |
int main (int argc, char const *argv[]) | |
{ | |
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; | |
Class<IdMethod> a = [IdClass class]; | |
NSLog(@"%@", [a method]); | |
Class<StructMethod> b = [StructClass class]; | |
NSLog(@"%@", NSStringFromRect([b method])); | |
[pool drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment