theWrapper 0.0.1

theWrapper 0.0.1

TestsTested
LangLanguage Obj-CObjective C
License BSD
ReleasedLast Release Dec 2014

Maintained by Unclaimed.


Downloads

Total4
Week0
Month0

Installs

Apps1
powered by Segment

GitHub

Stars73
Watchers8
Forks3
Issues1
Contributors1
Pull Requests0

Code

Files2
LOCLines of Code 130


  • By
  • Tomer Shiri

TheWrapper

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

What?!

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:^(va_list args)
    {
        NSLog(@"Hi,");
    }
    andPostRunBlock:^id(id functionReturnValue, va_list args)
    {
        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.

Known issues

  1. No arc support
  2. Wrapping a method that is only implemented in superclass results in a EXC_BAD_ACCESS.