From 63125724196e66906cfbc24cf3ff867a5a2261b3 Mon Sep 17 00:00:00 2001 From: Living Date: Tue, 11 Oct 2016 18:11:00 +0800 Subject: [PATCH] add @available to ConstraintLayoutGuide extension (#357) * add @available to ConstraintLayoutGuide extension * Modify #available --- Source/LayoutConstraintItem.swift | 1 + Tests/Tests.swift | 41 +++++++++++++++++-------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Source/LayoutConstraintItem.swift b/Source/LayoutConstraintItem.swift index 1025aba..fd7f213 100644 --- a/Source/LayoutConstraintItem.swift +++ b/Source/LayoutConstraintItem.swift @@ -31,6 +31,7 @@ public protocol LayoutConstraintItem: class { } +@available(iOS 9.0, *) extension ConstraintLayoutGuide : LayoutConstraintItem { } diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 870ec4b..295f408 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -62,26 +62,31 @@ 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 + if #available(iOS 9.0, *) { + 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") + + } else { + XCTAssertTrue(true) } - 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()