KVC (Key - Value - Code)鍵值編碼
// ITApp.h
#import <Foundation/Foundation.h>
@interface ITApp : NSObject
// 應(yīng)用名稱
@property(nonatomic, strong) NSString *name;
// 應(yīng)用圖片地址
@property(nonatomic, strong) NSString *icon;
// 應(yīng)用下載量
@property(nonatomic, strong) NSString *download;
// 字典轉(zhuǎn)模型的方法
+ (instancetype)ITAppWithDictionary:(NSDictionary *)dict;
@end
// ITApp.m
#import "ITApp.h"
#import <UIKit/UIKit.h>
@implementation ITApp
+(instancetype)ITAppWithDictionary:(NSDictionary *)dict
{
// 創(chuàng)建一個(gè) ITApp 對(duì)象
ITApp *app = [[ITApp alloc] init];
// KVC (Key - Value - Code)鍵值編碼;
[app setValuesForKeysWithDictionary:dict];
return app;
}
@end