bauerMusic
bauerMusic

Reputation: 6166

Identifying height/width constraints that are not NSContentSizeLayoutConstraint or similar

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.

Upvotes: 3

Views: 258

Answers (1)

bauerMusic
bauerMusic

Reputation: 6166

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!)

Upvotes: 2

Related Questions