All Projects → tomersh → TheWrapper

tomersh / TheWrapper

Licence: other
An objective C utility that lets you add a wrapper to any function.

Programming Languages

objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

TheWrapper

An objective C utility that lets you add a wrapper to any function.

##What is it?

Suppose you have the following method

//MyClass.m

-(void) foo {
  NSLog(@"My name is Mike");
}

with TheWrapper you can add a wrapper to foo in runtime. Just add the following code before the first call to the function.

//MyClass.m

#import "TheWrapper.h"

+(void) initialize {
    [TheWrapper addWrappertoClass:[MyClass class] andSelector:@selector(foo) withPreRunBlock:^(id<NSObject> zelf, id firstArg, ...) {
    {
        NSLog(@"Hi,");
    }
    andPostRunBlock:^id(id<NSObject> zelf, id functionReturnValue, id firstArg, ...) {
    {
        NSLog(@"Bye.");
    }];
}

Now, calling foo will print

[self foo];

//Hi,
//My name is Mike
//Bye,

The original function's return value is accessible to the PostRunBlock via the functionReturnValue parameter. If you wish to return the original return value, just return it from the PostRunBlock.

##Examples NanoProfiler is the first public usage of theWrapper.

##Known issues

  1. No arc support
  2. Wrapping a method that is only implemented in superclass results in a EXC_BAD_ACCESS.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].