diff --git a/Sources/Layout/NSLayoutConstraint.swift b/Sources/Layout/NSLayoutConstraint.swift index 4b6a695f..13d90d78 100644 --- a/Sources/Layout/NSLayoutConstraint.swift +++ b/Sources/Layout/NSLayoutConstraint.swift @@ -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 diff --git a/Tests/LayoutTests/NSLayoutConstraintTests.swift b/Tests/LayoutTests/NSLayoutConstraintTests.swift index ccff5986..36343b48 100644 --- a/Tests/LayoutTests/NSLayoutConstraintTests.swift +++ b/Tests/LayoutTests/NSLayoutConstraintTests.swift @@ -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