Identifying height/width constraints that are not NSContentSizeLayoutConstraint or similar

Viewed 147

I'm trying to 'grab' the width/height constraints of a view generically, that is, without setting an identifier/tag on the constraints. The system installs other constraints (such as NSContentSizeLayoutConstraint, but there are other private classes).

They are both NSLayoutConstraint class, same firstItem, Attribute and have similar properties in any property I can think of.

I'm looking for a way to differentiate between the ones I installed and the other ones.

1 Answers

This can be done using: NSStringFromClass(type(of:)) or String(describing: type(of:)), which will return NSContentSizeLayoutConstraint or NSLayoutConstraint.

if type(of: constraintInstance) == NSLayoutConstraint.self {
    // This is not a system constraint
}

(Thanks for Dale for the comparison help!)

Related