Giter Site home page Giter Site logo

blockinjection's Introduction

BlockInjection

BlockInjection is a helpful library for iOS and Mac OS X.

You can insert some Blocks before and after the method by this library.

Samples

For example, if you use Google Analytics, you can embed the code for tracking without polluting your original source code.

#import "BILib.h"

[BILib injectToClass:[ViewController class] selector:@selector(buttonDidPush:) preprocess:^{

  // This code is called just before buttnDidPush:
  [tracker sendEventWithCategory:@"uiAction"
                      withAction:@"buttonDidPush"
                       withLabel:nil
                       withValue:0];

}];

You can use NSString instead of Selector and Class.

#import "BILib.h"

[BILib injectToClassWithName:@"ViewController" methodName:@"buttonDidPush:" preprocess:^{

  // This code is called just before buttnDidPush:
  [tracker sendEventWithCategory:@"uiAction"
                      withAction:@"buttonDidPush"
                       withLabel:nil
                       withValue:0];

}];

You can insert a Postprocess.

#import "BILib.h"

[BILib injectToClass:[ViewController class] selector:@selector(buttonDidPush:) postprocess:^{

  // This code is called just after buttnDidPush:
  [tracker sendEventWithCategory:@"uiAction"
                      withAction:@"buttonDidPush"
                       withLabel:nil
                       withValue:0];

}];

You can use a instance method's argument in your block.

#import "BILib.h"

// Sample class

@interface Bizz : NSObject
- (void)sayMessage:(NSString*)message;
@end 

@implementation Bizz
- (void)sayMessage:(NSString*)message
{
  NSLog(@"Bizz says: %@", message);
}
@end 

// ...

[BILib injectToClass:[Bizz class] selector:@selector(sayMessage:) preprocess:^(Bizz* bizz, NSString* message){

  // This code is called just before buttnDidPush:
  [tracker sendEventWithCategory:@"Bizz"
                      withAction:@"sayMessage"
                       withLabel:message //< You can use the argument that is passed to sayMessage:
                       withValue:0];

}];

// ...

You can use the regex for specifying the class names and the method names.

#import "BILib.h"

[BILib injectToClassWithNameRegex:BIRegex(@"^UIView$") methodNameRegex:BIRegex(@"^set.*$") preprocess:^{

  // This code is called just before all UIView's setters and log the actual method name
  NSLog(@"%@", [BILib prettyFunction]);

}];

Getting Started - Installing BlockInjection

Please choose a way you prefer.

Using CocoaPods

// Podfile
pod 'BlockInjection'

and

pod install

Using Git

git clone git://github.com/tokorom/BlockInjection.git
// git submodule add git://github.com/tokorom/BlockInjection.git Externals/BlockInjection

and Add BlockInjection subdirectory to your Xcode's project.

Download a zip archive

Download
https://github.com/tokorom/BlockInjection/archive/master.zip
and Add BlockInjection subdirectory to your Xcode's project.

blockinjection's People

Contributors

tokorom avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.