1.项目里的资源通过主资源包加载到程序中
- 例如
NSBundle *bundle = [NSBundle mainBundle]; // 加载主资源包**
NSString *path = [bundle pathForResource:@"shops"ofType:@"plist"];
_shops= [NSArray arrayWithContentsOfFile:path]; // _shops为数组
2.懒加载(提高性能)需要的时候再加载也就是重新写get方法
- 例如
-(NSArray *)shops{
if(_shops ==nil){
NSBundle*bundle = [NSBundle mainBundle];
NSString*path = [bundle pathForResource:@"shops"ofType:@"plist"];
_shops= [NSArrayarrayWithContentsOfFile:path];
}
return _shops ; // _shops为数组
}
3.HUB(蒙板)
就是一个UILable,可以控制它什么时候显示,和隐藏。用 隐藏属性,与透明度来属性来实现。例如:
**UILable lable =[ [ UILable alloc] init];**
**Lable.Hiden = YES;// 用的是隐藏属性。
4.模型的创建与运用
- 4.1 首先新建一个类,用于描述模型数据
- 4.2 然后写一个初始化的方法。其中带有参数。用于初始化一个具体对象。例如传递进去一个字典返回一个模型数据
- 4.3 与模型有关的都封装在模型中
例如
```
- (id)initWithDict:(NSDictionary *) dict{
if(self = [super init]){
_name = dict[@"name"]; /
_icon = dict[@"icon"];
}
return self;
}
```
5.可以在懒加载中将字典数据转化为模型数据
好处是每次都加载一下,不用多次加载。
例如
- (NSArray *) shops
{
if(_shops ==nil){
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"shops"ofType:@"plist"];
NSArray * dictionArray = [NSArray arrayWithContentsOfFile:path];
NSMutableArray *shopArray = [NSMutableArray array];
for(NSDictionary *dict in dictionArray)
{
Shop *shop = [Shop shopWith:dict];
_shops = [shopsArray addObject: shop];
}
}
return _shops;
}```
###6.关于instancetype.
+ 6.1在类型上跟id一样,可以表示任何对象类型。
+ 6.2 只能用在返回值类型上,不能像id一样用在参数类型上。
+ 6.3 instancetype比id多一个好处。编译器会自动检测instancetype的真实类型。
###7.创建类的时候加上类前缀,例 YHshops,YHcar。
7.1方便团队成员知道代码的作者或者功能比较容易区分。
7.2 防止团队成员的类名冲突。