Skip to content

Instantly share code, notes, and snippets.

@mattyohe
Forked from PsychoH13/Evil.m
Created February 2, 2012 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattyohe/1720848 to your computer and use it in GitHub Desktop.
Save mattyohe/1720848 to your computer and use it in GitHub Desktop.
Debauching ObjC's dot-syntax and blocks in ObjC
#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