Skip to content

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

Description

@wolfcon

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"
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions