zoukankan      html  css  js  c++  java
  • 解析数据时,快速查看当前需要创建的数据模型的所有属性,不用每个都写,直接打印粘贴

    创建一个NSDictionary类别:

    #import <Foundation/Foundation.h>
    
    /**
     根据网络请求返回的字典数据,写对应的模型。当属性多时,用手写很费功夫,可用这个类快速打印出所有的模型属性,直接粘贴即可
     */
    @interface NSDictionary (PropertyCode)
    
    //生成需要的属性代码
    - (void)getPropertyCode;
    
    @end
    #import "NSDictionary+PropertyCode.h"
    
    @implementation NSDictionary (PropertyCode)
    
    //生成需要的属性代码
    - (void)getPropertyCode{
        NSMutableString *codes = [NSMutableString string];
        
        //遍历字典在所有的key一一对应
        [self enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
            //key:属性名
            NSString *code;
            if ([obj isKindOfClass:[NSString class]]) {
                code = [NSString stringWithFormat:@"@property (nonatomic ,strong) NSString *%@",key];
            }
            else if ([obj isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){
                code = [NSString stringWithFormat:@"@property (nonatomic ,assign) BOOL %@;",key];
            }
            else if ([obj isKindOfClass:[NSArray class]]) {
                code = [NSString stringWithFormat:@"@property (nonatomic ,strong) NSArray *%@",key];
            }
            else if ([obj isKindOfClass:[NSDictionary class]]) {
                code = [NSString stringWithFormat:@"@property (nonatomic ,strong) NSDictionary *%@",key];
            }
            else if ([obj isKindOfClass:[NSNumber class]]) {
                code = [NSString stringWithFormat:@"@property (nonatomic ,assign) NSInteger *%@",key];
            }
            
            [codes appendFormat:@"
    %@
    ",code];
        }];
        
        NSLog(@"数据模型属性------
    %@",codes);
    }
    
    @end
  • 相关阅读:
    暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns
    Help Jimmy ~poj-1661 基础DP
    POJ1015 && UVA
    FatMouse's Speed ~(基础DP)打印路径的上升子序列
    Max Sum Plus Plus
    Column Addition~DP(脑子抽了,当时没有想到)
    区间的连续段~ST表(模板题)
    Exponial~(欧拉函数)~(发呆题)
    wyh的数列~(坑爹题目)
    wyh的物品~(二分)
  • 原文地址:https://www.cnblogs.com/Crazy-ZY/p/5642677.html
Copyright © 2011-2022 走看看