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

父类、子类中都存在嵌套模型的数组,该如何处理 #855

Open
wv-y opened this issue Aug 31, 2023 · 1 comment
Open

父类、子类中都存在嵌套模型的数组,该如何处理 #855

wv-y opened this issue Aug 31, 2023 · 1 comment

Comments

@wv-y
Copy link

wv-y commented Aug 31, 2023

描述bug
mj_objectClassInArray 只获取了当前类的配置,如果子类执行后,不会获取父类中的配置
image

目前我是这么处理的,是否还有其他办法呢?

@interface MyA : NSObject
@property (nonatomic, strong) NSArray *list;
@end

@implementation MyA

+ (NSDictionary *)mj_objectClassInArray {
    return @{
        @"list" : MyA.class
    };
}

@end


@interface MyB : MyA
@property (nonatomic, strong) NSArray *bList;
@end

@implementation MyB

+ (NSDictionary *)mj_objectClassInArray {
    NSDictionary *superDict = [super mj_objectClassInArray];
    NSMutableDictionary *dict = @{
        @"bList" : MyB.class
    }.mutableCopy;
    if (superDict) {
        [dict addEntriesFromDictionary:superDict];
    }
    return dict;
}

@end
@wolfcon
Copy link
Collaborator

wolfcon commented Sep 11, 2023

你应该这样做:

  1. 首先判断父类是否实现了 mj_objectClassInArray
  2. 然后将父类跟子类进行合并

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