YYModel

//
//  ViewController.m
//  07_08
//
//  Created by Song on 2020/7/8.
//  Copyright © 2020 Song. All rights reserved.
//

#import "ViewController.h"
#import 
#import "YYPersonModel.h"

@interface ViewController () 

@property (nonatomic, strong) NSMutableArray *good;

@end

@implementation ViewController

#pragma mark - 懒加载
- (NSMutableArray *) good {
    if(_good == nil) {
        NSMutableArray *arrayModels = [NSMutableArray array];
        NSDictionary *dic = @{
            @"name":@"Zhang San",
            @"age":@(24),
            @"sex":@"Man",
            @"pic":@"coronavirus_02"
        };
        // 数据转模型
        YYPersonModel *model = [YYPersonModel yy_modelWithDictionary:dic];
        // 模型转数据
        //NSDictionary *dics = [model yy_modelToJSONObject];
       // NSLog(@"%@", model);//在类里面重写了description方法,使得可以输出,但是我在这输出不了。
        [arrayModels addObject:model];
        
        _good = arrayModels;
    }
    return _good;
    
}

#pragma mark - 数据源方法

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.good.count;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YYPersonModel *model = self.good[indexPath.row];
    static NSString *ID = @"goods_cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    cell.imageView.image = [UIImage imageNamed:model.pic];
    cell.textLabel.text = model.name;
    cell.detailTextLabel.text = [NSString stringWithFormat:@"性别:%@                  年龄:%d", model.sex, model.age];
    return cell;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
}



@end

你可能感兴趣的:(YYModel)