You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.
While writing tests for them, I noticed that in this test:
func testViewContraintsConstraintsWithMarginTraits() {
let view = UIView()
let superview = UIView()
superview.addSubview(view)
XCTAssertFalse(view.contains(trait: .TopMargin))
let topConstraint = view.topAnchor.constraint(equalTo: superview.topAnchor, constant: 30)
topConstraint.isActive = true
XCTAssertEqual(view.constraints(forTrait: .VerticalMargins), [topConstraint])
XCTAssertTrue(view.contains(trait: .VerticalMargins))
}
The second assertion will fail, as the implementation of contains(trait:) checks if the array of traits contains the passed in trait, whereas the the constraints(forTrait:) function checks if the passed in trait contains each constraint-on-the-view's trait.
I'm not sure why the contains(trait:) implementation isn't just calling constraints(forTrait: trait) and checking if the result is empty. But it seems like they should be consistent.
I'd suggest just removing/deprecating these methods as this sort of method in UIKit is for debugging only, and it's always better to store the constraints in a variable if they are needed rather than access them this way.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
While writing tests for them, I noticed that in this test:
The second assertion will fail, as the implementation of
contains(trait:)
checks if the array of traits contains the passed in trait, whereas the theconstraints(forTrait:)
function checks if the passed in trait contains each constraint-on-the-view's trait.I'm not sure why the
contains(trait:)
implementation isn't just callingconstraints(forTrait: trait)
and checking if the result is empty. But it seems like they should be consistent.I'd suggest just removing/deprecating these methods as this sort of method in UIKit is for debugging only, and it's always better to store the constraints in a variable if they are needed rather than access them this way.
The text was updated successfully, but these errors were encountered: