Created
May 5, 2014 22:07
-
-
Save oleksii-demedetskyi/a552acb505ad07105acb to your computer and use it in GitHub Desktop.
Example trait usage.
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> | |
#define trait(NAME) protocol NAME;\ | |
@interface id_##NAME @end \ | |
typedef id_##NAME<NAME> NAME; \ | |
@protocol NAME | |
#define trait_implementation(NAME) \ | |
interface NAME##_impl : NSObject<NAME>\ | |
- (NAME *) asTrait$;\ | |
@end \ | |
@implementation NAME##_impl \ | |
- (NAME *) asTrait$ { return (NAME*)self; }\ | |
@trait(SomeInterface) | |
@property (nonatomic, retain) NSString* test; | |
- (void)printTest; | |
@end | |
@trait_implementation(SomeInterface) | |
@synthesize test; | |
- (void)printTest | |
{ | |
NSLog(@"Test is: %@", self.test); | |
} | |
@end | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
SomeInterface* testObject = [SomeInterface_impl new].asTrait$; | |
testObject.test = @"Check"; | |
[testObject printTest]; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://cl.ly/image/3R0h2f31292a/Снимок%20экрана%202014-05-06%20в%2001.13.09.png