Skip to content

Instantly share code, notes, and snippets.

@onmyway133
Last active April 24, 2019 13:22
Show Gist options
  • Save onmyway133/90e95a11c6d17b04d9069b4bb1a017de to your computer and use it in GitHub Desktop.
Save onmyway133/90e95a11c6d17b04d9069b4bb1a017de to your computer and use it in GitHub Desktop.
public extension Anchor {
/// Find a constraint based on an attribute
func find(_ attribute: Attribute) -> NSLayoutConstraint? {
guard let view = item as? View else {
return nil
}
var constraints = view.superview?.constraints
if attribute == .width || attribute == .height {
constraints?.append(contentsOf: view.constraints)
}
return constraints?.filter({
guard $0.firstAttribute == attribute else {
return false
}
guard $0.firstItem as? NSObject == view else {
return false
}
return true
}).first
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment