DynamicOC是一个功能上与JSPath类似,但是仅需要编写原生OC语法就能实现热更新(hotfix)的功能。
- 动态执行OC代码
- 动态执行C函数和block异步调用
- 动态添加属性
- 动态替换方法
- 动态添加方法
- 有完善的单元测试
- flex/yacc实现强大的OC语法解析器
- 支持CGRect/CGSize/CGPoint/NSRange/UIEdgeInsets/CGAffineTransform常用结构体 ...
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);
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);
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);
- if/else while do/while for
- return break continue
- i++ i-- ++i --i
- +i -i !i
- + - * / %等四则运算
- >> << & | ^ 等位运算
- && || >= <= != > < 等比较运算
- ?:
- __block
- array[i] dict[@""]
- @666 @() @[] @{}
- self super
- self.property
- self->_property
- most of objective-c keyword
- @available()
- [NSString stringWithFormat:"%d",value] : use [NSString stringWithFormat:"%@",@(value)] instead。
- dispatch_async / dispatch_after ...
- *stop =YES, in block
- fix bugs
- GitHub : letqingbin
- Email : letqingbin@163.com
纯粹是技术分享,鉴于JSPath的被禁,不建议用于上架Appstore。
Copyright (c) 2019 letqingbin
Licensed under MIT or later
DynamicOC required features are based on or derives from projects below: