侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

基于flex/yacc的iOS热更新框架

2022-07-01 星期五 / 0 评论 / 0 点赞 / 47 阅读 / 6989 字

中文介绍 | 原理介绍 A hotfix library based on flex/yacc. You can call any Objective-C cla

中文介绍 | 原理介绍

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 dKingbinLicensed under MIT or later

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

.
.

广告 广告

评论区