一次github关于JSONModel的issues经历, lazy conversion 与 ConvertOnDemand
问题
我自定义了个NSArray的Category避免数组越界,典型的方法是 (issue地址)
1 2 3 4 5 6 7 |
-(id)objectWithIndex:(NSUInteger)index{ if (index <self.count) { return self[index]; }else{ return nil; } } |
Folder 实体
1 2 3 4 5 6 7 8 9 10 11 |
#import "JSONModel.h" @protocol Folder @end @interface Folder : JSONModel @property(nonatomic,copy) NSString *folder; @property(nonatomic,copy) NSString *name; @property(nonatomic,copy) NSString *key; @property(nonatomic,copy) NSString *icon; @end |
Model 实体
1 2 3 4 5 |
#import "JSONModel.h" #import "Folder.h" @interface Model : JSONModel @property(nonatomic,strong) NSArray<Folder,ConvertOnDemand> *appearances; @end |
然后使用
1 2 3 |
Model *model = [[Model alloc] initWithString:json error:&err]; Folder *folder = [model.appearances objectWithIndex:index]; NSString *name = folder.name; |
folder 变成了 NSDictionary 实例,不是一个Folder实例
当访问其属性时,直接崩溃
一个JSONModel库贡献者(billinghamj )的回复
1.You're making a category on NSArray, but JSONModelArray isn't an NSArray - it doesn't subclass NSArray.
If you need to rely on the exact behavior of an actual NSArray, don't use ConvertOnDemand.
(我心想我特么还不知道他不是NSArray的子类啊,所以才又bug啊)
2.That being said, I think we probably should just subclass NSArray...
@icanzilb(这块@了JSONModel作者) Any reason we don't subclass NSArray? We're currently just making an NSArray-like class, but not subclassing it.
接着pull request了个 Rebuild JSONModelArray as an NSArray subclass #464 ,我进去一看把JSONModelArray父类改成了NSArray,删除了一堆方法....然后原来作者icanzilb和billinghamj撕了会逼.....很精彩 哈哈哈哈哈啊哈哈哈哈哈哈哈哈
然后又 @了我Could you try this again against my PR #464?
然后又 @了我Okay, we've officially removed support for ConvertOnDemand
as it no longer serves a practical purpose. Simply remove the protocol from your property and everything will work as expected.
最终关闭了issu
我早晨礼貌的回复了个 it works,thanks......
pull了一下:
JSONModel no longer supports lazy conversion
billinghamj committed 10 hours ago
Remove all support for ConvertOnDemand
billinghamj committed 10 hours ago
茉莉花香啊.....
转载请注明:天狐博客 » 一次github为JSONModel提issues经历