【发布时间】:2015-09-13 16:06:19
【问题描述】:
这是我的真实代码:
@IBOutlet weak var contentTextView: SmartTextView! {
didSet {
self.contentTextView.onDidBeginEditing = {
$0.layer.borderColor = Util.green.CGColor
}
self.contentTextView.onDidEndEditing = {
$0.layer.borderColor = Util.gray.CGColor
}
self.contentTextView.layer.borderWidth = 1 / Util.screenScale
self.contentTextView.layer.borderColor = Util.gray.CGColor
self.contentTextView.minHeight = 148
self.contentTextView.maxHeight = 148
self.contentTextView.onChange = { [unowned self] text in
var content = text.stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "\n\t"))
self.contentLenthLabel.text = "\(self.MAX_CONTENT - count(content))"
}
}
}
如果我删除 [unowned self] 语句,我可以在 Instruments 中看到保留周期问题。
KVO 或其他东西使弱 var 仍然会导致保留循环吗?
【问题讨论】:
-
@matt 既然 contentTextView 是一个弱变量,我认为无论 SmartTextView 是如何实现的,它都不应该导致保留周期。我错了吗?而且我确信保留周期是真实的。顺便说一句,SmartTextView 只是 UITextView 的一个子类,我写它来模仿 UILabel 的占位符功能并添加自动增长功能,如果您需要,我可以显示代码。
标签: ios retain-cycle