Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

最新版本模型中带有下划线会导致Carsh #23

Open
HuaZao opened this issue Apr 3, 2016 · 2 comments
Open

最新版本模型中带有下划线会导致Carsh #23

HuaZao opened this issue Apr 3, 2016 · 2 comments

Comments

@HuaZao
Copy link

HuaZao commented Apr 3, 2016

比如在Model定义 school_code 这种带下划线的变量名会导致Carsh

@xuzixian
Copy link

xuzixian commented Apr 5, 2016

我也遇到了,怎么解决

@xuzixian
Copy link

xuzixian commented Apr 5, 2016

目前有一取巧方法:在NSObject+Runtime.m文件的+(void)enumerateCls: propertyBlock:的实现代码改成:
+(void)enumerateCls:(Class)cls propertyBlock:(void(^)(CoreProperty *p))propertyBlock{

unsigned int numIvars; //成员变量个数

Ivar *vars = class_copyIvarList(cls, &numIvars);

//Ivar *vars = class_copyIvarList([UIView class], &numIvars);

NSString *key=nil;
NSString *type = nil;

for(int i = 0; i < numIvars; i++) {

    //创建CoreProperty
    CoreProperty *p =[CoreProperty new];

    Ivar thisIvar = vars[i];
    key = [NSString stringWithUTF8String:ivar_getName(thisIvar)];  //获取成员变量的名字

    if ([[key substringWithRange:NSMakeRange(0, 1)] isEqualToString:@"_"]) {
        key = [key substringFromIndex:1];
    }
    //记录变量名
    p.name = key;

    type = [NSString stringWithUTF8String:ivar_getTypeEncoding(thisIvar)]; //获取成员变量的数据类型

    //处理并记录变量类型
    p.code = type;

    propertyBlock(p);
}

free(vars);

}

添加了
if ([[key substringWithRange:NSMakeRange(0, 1)] isEqualToString:@"_"]) {
key = [key substringFromIndex:1];
}
只去掉第一个 _

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants