-
-
Save mattyohe/1720848 to your computer and use it in GitHub Desktop.
Debauching ObjC's dot-syntax and blocks in ObjC
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 NSString (Evil) | |
@property(assign, setter=initWithString:) NSString *initWithString; | |
@property(assign, readonly) NSString *test; | |
@property(assign, readonly) NSArray *(^split)(NSString *); | |
@end | |
int main(int argc, char *argv[]) | |
{ | |
NSAutoreleasePool *pool = ((NSObject *)NSAutoreleasePool.alloc).init; | |
NSString *str = (((NSString *)NSString.alloc).initWithString = @"My big evil string").test.autorelease; | |
NSLog(@"%@", str.split(@" ")); | |
NSLog(@"%@", str); | |
pool.drain; | |
return 0; | |
} | |
@implementation NSString (Evil) | |
@dynamic initWithString; | |
- (NSString *)test | |
{ | |
NSLog(@"%s %@", __FUNCTION__, super.description); | |
return self; | |
} | |
- (NSArray *(^)(NSString *))split | |
{ | |
return [[^(NSString *sep){ | |
return [self componentsSeparatedByString:sep]; | |
} copy] autorelease]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment