YSInit 1.0.4

YSInit 1.0.4

Maintained by ys.



YSInit 1.0.4

  • By
  • ys

YSInit

初始化的语法糖

环境

swift5.0、iOS10.0

安装使用

1、导入框架

pod 'YSInit'

2、导入命名空间

import YSInit

简单介绍

// class的then语法糖:设置自身属性、或对自身操作,返回自己
// 默认NSObject遵守了YSThen协议
extension NSObject: YSThen{}
private lazy var testV:UIView = UIView().ysThen{ $0.backgroundColor = UIColor.white }

// 如果自定义的类要想实现then语法糖,只需要遵守YSThen协议即可
class ViewController: UIViewController {
    private lazy var dog:Dog = Dog().ysThen{ $0.name = "辛巴" }
}

class Dog {
    var name = ""
}

// 遵守YSThen协议
extension Dog: YSThen{}
// 提供了一个工具类YSInit,为以下控件提供快捷创建对象的方法,当然完全可以使用then语法设置
// 调用:YSInit.类名去掉系统前缀
// 如:YSInit.view、YSInit.label、YSInit.button……
/*
UIAlertAction、UIBarButtonItem、UIButton、CGRect、UICollectionView、UICollectionViewCell、UIColor、UIImage、UIImageView、UILabel、UIPasteboard、UIProgressView、UIScrollView、UISwitch、UITableView、UITableViewCell、URL
*/

// 注意:UITableView、UICollectionView创建空白Cell,一定要保证注册了identifier = "ysCellID_nothing"

感谢

最后感谢devxoul大神,then语法糖是根据devxoul大神的Then库转化来的,详见:https://github.com/devxoul/Then