jsonmodel / jsonmodel

Magical Data Modeling Framework for JSON - allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS and tvOS apps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Convenient way to ignore/optional *multiple* variable

willard1218 opened this issue · comments

I have scalar types need to ignore, like this :

@interface PeopleModel : JSONModel
@property (nonatomic, strong) NSString *name;
@property (nonatomic) NSUInteger no;
@property (nonatomic) NSUInteger age;
@end

@implementation PeopleModel
+ (BOOL)propertyIsIgnored:(NSString *)propertyName {
    if ([propertyName isEqualToString:@"no"])
        return YES;

    if ([propertyName isEqualToString:@"age"])
        return YES;

    return NO;
}
@end

If I have a lot of scalar types to ignore, this method become large,

So I write a convenient method to ignore/optional multiple variable.
willard1218@e84828e

Now, I can ignore scalar types like this :

@interface PeopleModel : JSONModel
@property (nonatomic, strong) NSString *name;
@property (nonatomic) NSUInteger no;
@property (nonatomic) NSUInteger age;
@end

@implementation PeopleModel
+ (NSArray <NSString *>*)ignoredProperties {
    return @[@"no", @"age"];
}
@end

Why not just do this?

@implementation PeopleModel
+ (BOOL)propertyIsIgnored:(NSString *)propertyName {
    return [@[@"no", @"age"] containsObject:propertyName];
}
@end

I see, you are right.