6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NSLayoutConstraintをIBOutletで保持する場合の注意点

Posted at

NSLayoutConstraintをIBOutletで紐づける場合、普通はこうなると思います。

@IBOutlet fileprivate weak var constraint: NSLayoutConstraint!

しかし、このconstraintを非activeにするとマズいことが起きたりします。

constraint.isActive = false
constraint.constant = 10 /// 強制終了する

どうも非activeになったタイミングでretainCountがなくなり、解放されてしまうようです。
そのため、この場合に限ってはweakは付けないのが正解なのかな、と思っています。
本当の正解をご存知の方がいらっしゃいましたらコメントいただけますと幸いです。。

6
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?