diff --git a/Source/ConstraintDSL.swift b/Source/ConstraintDSL.swift index cda83a0..ed7b7e5 100644 --- a/Source/ConstraintDSL.swift +++ b/Source/ConstraintDSL.swift @@ -49,12 +49,12 @@ extension ConstraintDSL { private var labelKey: UInt8 = 0 -public protocol ConstraintAttributesDSL: ConstraintDSL { +public protocol ConstraintBasicAttributesDSL : ConstraintDSL { } -extension ConstraintAttributesDSL { +extension ConstraintBasicAttributesDSL { // MARK: Basics - + public var left: ConstraintItem { return ConstraintItem(target: self.target, attributes: ConstraintAttributes.left) } @@ -107,6 +107,12 @@ extension ConstraintAttributesDSL { return ConstraintItem(target: self.target, attributes: ConstraintAttributes.center) } +} + +public protocol ConstraintAttributesDSL : ConstraintBasicAttributesDSL { +} +extension ConstraintAttributesDSL { + // MARK: Baselines @available(*, deprecated:3.0, message:"Use .lastBaseline instead") diff --git a/Source/ConstraintLayoutGuideDSL.swift b/Source/ConstraintLayoutGuideDSL.swift index 62bd9b4..d5b1949 100644 --- a/Source/ConstraintLayoutGuideDSL.swift +++ b/Source/ConstraintLayoutGuideDSL.swift @@ -31,6 +31,27 @@ @available(iOS 9.0, *) public struct ConstraintLayoutGuideDSL: ConstraintAttributesDSL { + @discardableResult + public func prepareConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] { + return ConstraintMaker.prepareConstraints(item: self.guide, closure: closure) + } + + public func makeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { + ConstraintMaker.makeConstraints(item: self.guide, closure: closure) + } + + public func remakeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { + ConstraintMaker.remakeConstraints(item: self.guide, closure: closure) + } + + public func updateConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { + ConstraintMaker.updateConstraints(item: self.guide, closure: closure) + } + + public func removeConstraints() { + ConstraintMaker.removeConstraints(item: self.guide) + } + public var target: AnyObject? { return self.guide } diff --git a/Tests/Tests.swift b/Tests/Tests.swift index c00beb4..870ec4b 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -60,6 +60,29 @@ class SnapKitTests: XCTestCase { } + func testGuideMakeConstraints() { + let v1 = View() + let g1 = UILayoutGuide() + + self.container.addSubview(v1) + self.container.addLayoutGuide(g1) + + v1.snp.makeConstraints { (make) -> Void in + make.top.equalTo(g1.snp.top).offset(50) + make.left.equalTo(g1.snp.top).offset(50) + return + } + + XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed") + + g1.snp.makeConstraints { (make) -> Void in + make.edges.equalTo(v1) + return + } + + XCTAssertEqual(self.container.snp_constraints.count, 6, "Should have 6 constraints installed") + } + func testMakeImpliedSuperviewConstraints() { let v1 = View() let v2 = View()