Last active
April 24, 2019 13:22
-
-
Save onmyway133/90e95a11c6d17b04d9069b4bb1a017de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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