self
1.问题: error: use of unresolved identifier 'self'
2.出现的地方:在构造函数之前,在属性生成器中打印self得到的错误
3.出现错误的代码如下:
/// 本来打算使用懒加载,但是lazy关键字被遗漏,所以在这里eyeButton就是一个闭包生成属性(在初始化方法前执行)
/// 测试中发现 事件始终不响应,打断点发现这个问题
fileprivate var eyeButton: UIButton = {
let btn = UIButton(type: .custom)
btn.addTarget(self, action: #selector(eyeButtonClick(sender:)), for: .touchUpInside)
return btn
}()
4.原因: 在构造函数调用前执行的函数和闭包里面的self是未指定的
5.问题结论:
- 使用self不会产生错误,尽管他不存在(这导致很容易忽略潜在问题)
- 在使用p po打印self时,才会得到大标题文案的错误