Git Product home page Git Product logo

dynamicoc's Introduction

中文介绍 | 原理介绍

DynamicOC

A hotfix library based on flex/yacc. You can call any Objective-C class and method using DynamicOC. DynamicOC is functionally similar to JSPath, but it only needs to write native OC syntax to implement hotfix.

Features

  • dynamically execute Objective-C code
  • dynamically execute C function and block
  • dynamically add property
  • dynamically replace method
  • dynamically add method
  • Completed and detailed unit test
  • powerful OC syntax parser based on flex/yacc
  • support CGRect/CGSize/CGPoint/NSRange/UIEdgeInsets/CGAffineTransform C-struct ...

Basic Usage

dynamically execute block

NSString* text = @" \
__block int result = 0;\
UIView* view = [[UIView alloc]init];\
void(^blk)(int value) = ^(int value){\
    view.tag = value;\
};\
blk(1024);\
return view.tag;";

ASTNode* root = [ASTUtil parseString:text];
ASTVariable* result = [root execute];
NSAssert([result.value doubleValue] == 1024, nil);

dynamically execute C function

int echo(int value) {
    return value;
}

NSString* text = @" \
[OCCfuntionHelper defineCFunction:@\"echo\" types:@\"int, int\"]; \
return echo(1024);";

ASTNode* root = [ASTUtil parseString:text];
ASTVariable* result = [root execute];
NSAssert([result.value doubleValue] == 1024, nil);

dynamically add property

NSString* text = @" \
[OCCfuntionHelper defineCFunction:@\"objc_setAssociatedObject\" types:@\"void,id,void *,id,unsigned int\"];\
[OCCfuntionHelper defineCFunction:@\"objc_getAssociatedObject\" types:@\"id,id,void *\"];\
NSString* key = @\"key\"; \
objc_setAssociatedObject(self, key, @(1024), 1);\
return objc_getAssociatedObject(self, key);";

ASTNode* root = [ASTUtil parseString:text];
ASTVariable* result = [root execute];
NSAssert([result.value doubleValue] == 1024, nil);

Supported Syntax

  • if/else while do/while for
  • return break continue
  • i++ i-- ++i --i
  • +i -i !i
  • + - * / % Arithmetic operation
  • >> << & | ^ Bit operation
  • && || >= <= != > < Compare operation
  • ?:
  • __block
  • array[i] dict[@""]
  • @666 @() @[] @{}
  • self super
  • self.property
  • self->_property
  • most of objective-c keyword

TODO

  • @available()
  • [NSString stringWithFormat:"%d",value] : use [NSString stringWithFormat:"%@",@(value)] instead。
  • dispatch_async / dispatch_after ...
  • *stop =YES, in block
  • fix bugs

Communication

Warnning

Purely technology sharing, DO NOT Sheld to appstore! 

License

Copyright (c) 2019 letqingbin
Licensed under MIT or later

DynamicOC required features are based on or derives from projects below:

dynamicoc's People

Contributors

letqingbin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dynamicoc's Issues

还是不能上架嘛

你好, 还是不能上架嘛,如果完全不能热更,那那些大厂的小程序怎么实现的

线上如何使用

你好,我看到的都只是本地的代码,要如何通过线上更新?
我看使用的是以下的方法,发布之后出现bug,那要怎么实现?

[DynamicOC hookClass:@"ViewController"
                selector:@"tableView:cellForRowAtIndexPath:"
                argNames:@[@"tableView",@"indexPath"]
                 isClass:NO
          implementation:cellForRowAtIndexPath];

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.