美文网首页
Swift 记录 --- 懒加载(lazy)

Swift 记录 --- 懒加载(lazy)

作者: 8a420e49153d | 来源:发表于2018-06-25 15:43 被阅读30次

    1.简单写法

    
    private lazy var imageArr: NSMutableArray  = NSMutableArray() 
    
    private lazy var dataArr: NSMutableArray  = NSMutableArray()
    
    

    2.闭包

    
    private lazy var customView: UIView = { 
        let customView = UIView(frame:CGRectMake(0,0,W,H)) 
        customView.backgroundColor = UIColor.whiteColor()
        customView.alpha = 0.0
        return customView 
    }()
    
    

    相关文章

      网友评论

          本文标题:Swift 记录 --- 懒加载(lazy)

          本文链接:https://www.haomeiwen.com/subject/fjeyyftx.html