模型
--什么事模型?
—专门用来存放数据的对象
-一般都是继承至NSObject的纯对象
-内部会提供一些属性支持模型
控制器主要做的是管理view
#import <Foundation/Foundation.h>
@interface Shop : NSObject
/** 商品名称 */
@property(nonatomic,strong)NSString * name ;
/** 商品图片 */
@property(nonatomic,strong)NSString * icon ;
-(id)initWithDict:(NSDictionary*)dict;
+(id)shopWithDict:(NSDictionary*)dict;
@end
#import "Shop.h"
@implementation Shop
-(id)initWithDict:(NSDictionary*)dict
{
if(self==[super init])
{
self.name=dict[@"name"];
self.icon=dict[@"icon"];
}
return self;
}
+(id)shopWithDict:(NSDictionary*)dict
{
return [[self alloc]initWithDict:dict];
}
@end
NSDictionary *dict = self.shops[index];
Shop *shop=[Shop shopWithDict:dict];