JSPatch icon indicating copy to clipboard operation
JSPatch copied to clipboard

能否在defineClass中创建OC的属性,因为现在新加属性只能在补丁中使用

Open yeahdongcn opened this issue 9 years ago • 5 comments

NSArray *propertyArray = [properties toArray];
for (NSString *propertyName in propertyArray) {
    class_addProperty(cls, [propertyName UTF8String], attributes, attributeCount);
}

yeahdongcn avatar Jun 24 '16 03:06 yeahdongcn

遇到的一个实际情况就是我们在用Mantle做JSON到Model的转换,但是有个字段少了,写了个js增加了property和key的对应关系,但是Mantle在遍历属性的时候找不到就报错了。

yeahdongcn avatar Jun 24 '16 07:06 yeahdongcn

我在使用 JSONModel 的时候也遇到过,最后的解决方法是通过 JSPatch 添加属性,然后重写 init 方法手动赋值。

jiyee avatar Jun 24 '16 15:06 jiyee

我再考虑下怎样加上这个功能

bang590 avatar Jun 25 '16 15:06 bang590

我感觉麻烦的地方是现有的声明属性的地方怎么兼容还有就是是否要带类型

yeahdongcn avatar Jun 27 '16 00:06 yeahdongcn

新建一个类,完全覆盖本地的类、???能否可行

icoder20150719 avatar Jun 30 '16 07:06 icoder20150719