Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

ConstraintTraitMask inconsistencies? #20

Open
Jon889 opened this issue Jun 12, 2018 · 0 comments
Open

ConstraintTraitMask inconsistencies? #20

Jon889 opened this issue Jun 12, 2018 · 0 comments

Comments

@Jon889
Copy link
Contributor

Jon889 commented Jun 12, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant