GithubHelp home page GithubHelp logo

wateringxx / lokie Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alibaba/lokie

0.0 1.0 0.0 277 KB

iOS efficient AOP Library using C++ and libffi

License: MIT License

C 63.21% Objective-C 4.09% Objective-C++ 24.51% C++ 8.19%

lokie's Introduction

LOKIE

A framework for building iOS AOP.

Support iOS 8.0+

building Lokie

  • open Lokie.xcodeproj with Xcode and build it
  • defualt configuration will build Lokie.framework for you
  • you can use Lokie.framework as other normal framework in your project
  • Enjoy it.

Use Lokie

API

//! Lokie.h
#import <Foundation/Foundation.h>

typedef enum : NSUInteger {
    LokieHookPolicyBefore = 1 << 0,
    LokieHookPolicyAfter = 1 << 1,
    LokieHookPolicyReplace = 1 << 2,
    LokieHookPolicyPatchEnv = 1 << 3,
} LokieHookPolicy;

@interface NSObject (Lokie)

+ (BOOL) Lokie_hookMemberSelector:(NSString *) selecctor_name
                        withBlock: (id) block
                           policy:(LokieHookPolicy) policy;

+ (BOOL) Lokie_hookClassSelector:(NSString *) selecctor_name
                       withBlock: (id) block
                          policy:(LokieHookPolicy) policy;

+ (BOOL) Lokie_resetSelector:(NSString *) selector_name withType:(BOOL) isMember;

+ (NSArray *) LokieErrorStack;

@end

How to use

#include <Lokie/Lokie.h>

//! insert something before UIViewController::viewDidAppear:
Class cls = NSClassFromString(@"UIViewController");
[cls Lokie_hookMemberSelector:@"viewDidAppear:" withBlock:^(id target, BOOL ani){
        NSLog(@"LOKIE: before viewDidAppear");
 }policy:LokieHookPolicyBefore];

[cls Lokie_hookMemberSelector:@"viewDidAppear:" withBlock:^(id target, BOOL ani){
         NSLog(@"LOKIE: after viewDidAppear");
 }policy:LokieHookPolicyAfter];
 
//! we can insert some code before/after 
Class cls = NSClassFromString(@"MyViewController");
[cls Lokie_hookMemberSelector:@"initWithConfig:"
                    withBlock:^(id target, NSDictionary *param){
                        NSLog(@"%@", param);
                        NSLog(@"Lokie: %@ is created", target);
} policy:LokieHookPolicyAfter];
    
//! hooked selector does not has any param
[cls Lokie_hookMemberSelector:@"dealloc" withBlock:^(id target){
        NSLog(@"Lokie: %@ is dealloc", target);
} policy:LokieHookPolicyBefore];

lokie's People

Contributors

fliggy avatar

Watchers

James Cloos 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.