最新消息:iOS编程开发交流群(6906921) ,Mac.Cocoa开发交流群(7758675) 欢迎iOS/macOS开发编程爱好及学习者加入!

一次github为JSONModel提issues经历

iOS 天狐 6738浏览 0评论

一次github关于JSONModel的issues经历, lazy conversion 与 ConvertOnDemand

2DB49770-DFFC-4605-8C8D-46B600C47EFA

问题

我自定义了个NSArray的Category避免数组越界,典型的方法是 (issue地址)

-(id)objectWithIndex:(NSUInteger)index{
    if (index <self.count) {
        return self[index];
    }else{
        return nil;
    }
}

Folder 实体

#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 实体

#import "JSONModel.h"
#import "Folder.h"
@interface Model : JSONModel
@property(nonatomic,strong) NSArray<Folder,ConvertOnDemand> *appearances;
@end

然后使用

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经历

微信 OR 支付宝 扫描二维码
为天狐 打赏
非常感谢你的支持,哥会继续努力!
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址