Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 435 Bytes

swift02.md

File metadata and controls

27 lines (20 loc) · 435 Bytes

Swift中延迟加载

Objective-c中延迟加载

@property(nonatomic, strong) UILabel *nameLbl;
	
- (UILabel *)nameLbl{
	if(!_nameLbl){
	   _nameLbl = [[UILabel alloc] init];
	}
	return _nameLbl;
}	

Swift中延迟加载

//在属性定义的地方,使用闭包来实例化属性
lazy var nameLbl:UILabel? = {
	var tmpLbl = UILabel()
	tmpLbl.textColor = UIColor.blackColor()
	return tmpLbl
}()