Skip to content

Commit

Permalink
Add attribute property to NSLayoutConstraint.Axis (#144)
Browse files Browse the repository at this point in the history
* Add attribute property to NSLayoutConstraint.Axis

* Fix order

* Fix order

* Remove spaces
  • Loading branch information
tinder-garricnahapetian authored Oct 16, 2023
1 parent 40b743b commit 7f82a00
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Sources/Layout/NSLayoutConstraint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,25 @@ extension NSLayoutConstraint.Axis {

internal var orientation: String {
switch self {
case .vertical:
return "V"
case .horizontal:
return "H"
case .vertical:
return "V"
@unknown default:
return "H"
}
}

internal var attribute: NSLayoutConstraint.Attribute {
switch self {
case .horizontal:
return .centerX
case .vertical:
return .centerY
@unknown default:
return .notAnAttribute
}
}
}

// MARK: - NSLayoutConstraint Array Helpers
Expand Down
13 changes: 13 additions & 0 deletions Tests/LayoutTests/NSLayoutConstraintTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ final class NSLayoutConstraintTests: XCTestCase {
expect(verticalAxis.orientation) == "V"
}

func testAxisAttribute() {

// GIVEN

let horizontalAxis: NSLayoutConstraint.Axis = .horizontal
let verticalAxis: NSLayoutConstraint.Axis = .vertical

// THEN

expect(horizontalAxis.attribute) == .centerX
expect(verticalAxis.attribute) == .centerY
}

func testBatchActivation() {

// GIVEN
Expand Down

0 comments on commit 7f82a00

Please sign in to comment.