zoukankan      html  css  js  c++  java
  • ios 根据字典自动生成属性

    - (void)createPropertyCode
    {
    NSMutableString *codes = [NSMutableString string];
    // 遍历字典
    [self enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull value, BOOL * _Nonnull stop) {
    NSString *code;
    if ([value isKindOfClass:[NSString class]]) {

    code = [NSString stringWithFormat:@"@property (nonatomic, copy) NSString *%@",key];

    }else if ([value isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){

    code = [NSString stringWithFormat:@"@property (nonatomic, assion) BOOL %@",key];

    }else if ([value isKindOfClass:NSClassFromString(@"__NSCFNumber")]){

    code = [NSString stringWithFormat:@"@property (nonatomic, assion) NSInteger %@",key];

    }else if ([value isKindOfClass:NSClassFromString(@"__NSArrayI")]){

    code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSArray *%@",key];

    }else if ([value isKindOfClass:NSClassFromString(@"__NSCFDictionary")]){

    code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSDictionary *%@",key];

    }

    [codes appendFormat:@" %@ ",code];

    }];
    NSLog(@"codes = %@",codes);
    }

  • 相关阅读:
    在归并排序中对小数组采用插入排序实现代码
    PAT 1032. Sharing
    1031. Hello World for U
    PAT 1030. Travel Plan
    PAT 1029. Median
    PAT 1028. List Sorting
    PAT 1027. Colors in Mars
    PAT 1026. Table Tennis
    PAT 1025. PAT Ranking
    Several Important Commands in GMT
  • 原文地址:https://www.cnblogs.com/soulDn/p/10567787.html
Copyright © 2011-2022 走看看