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

增加模型配置方法的继承保留或不保留选择方案 #836

Open
wolfcon opened this issue Dec 29, 2021 · 0 comments · Fixed by #789
Open

增加模型配置方法的继承保留或不保留选择方案 #836

wolfcon opened this issue Dec 29, 2021 · 0 comments · Fixed by #789

Comments

@wolfcon
Copy link
Collaborator

wolfcon commented Dec 29, 2021

mj_shouldAutoInheritConfigurations

原有方案

mj_setup block 设置会自动继承
mj_ 非 block 方法设置不会自动继承

逻辑

这里以 mj_replacedKeyFromPropertyName 为例:

/// 父类: 
@interface MJUser : NSObject <MJEConfiguration>
...
@end

@implementation MJUser
+ (NSDictionary *)mj_replacedKeyFromPropertyName {
    return @{
        @"speed": @"runSpeed"
    };
}
@end

/// 子类:
@interface MJFrenchUser : MJUser
...
@end

@implementation MJFrenchUser
+ (NSDictionary *)mj_replacedKeyFromPropertyName {
    return @{
        @"nickname": @"surnom"
    };
}
@end

原有逻辑

最终 MJUser 的替换列表为

@{
    @"speed": @"runSpeed"
};

而 MJFrenchUser 的替换列表为

@{
    @"nickname": @"surnom"
};

改进方案

提供选择继承与否的方法 mj_shouldAutoInheritConfigurations, 默认为继承, 如果设置为否. 则不保留继承, 与原方案一致
否则保留默认继承的话 MJFrenchUser 的替换列表应为

@{
    @"speed": @"runSpeed",
    @"nickname": @"surnom"
};
@wolfcon wolfcon linked a pull request Dec 29, 2021 that will close this issue
@wolfcon wolfcon added this to the 4.0.0 milestone Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant