Andrey Chernukha Andrey Chernukha - 4 months ago 63
iOS Question

Why weak IBOutlet NSLayoutConstraint turns to nil when I make it inactive?

I have an

IBOutlet NSLayoutConstraint
in my app. Very simple:

@property (nonatomic, weak) IBOutlet NSLayoutConstraint* leftConstraint;

At some point I want to deactivate this constraint: = NO;

It happens in a method called from
. And the constraint becomes nil right after the line above. However if I declare this property as
then it's ok, it doesn't turn to nil. Can anybody explain why it happens?

Avi Avi

When your outlet is weak, the only strong reference is from the view's constraints property. Deactivating the constraint removes it from that array, so there are no more strong references.