From fc298aeaf41ba00088bb9d353acfe26fb10ccf9b Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Fri, 2 Sep 2016 00:27:26 +1200 Subject: [PATCH] Split up DSL and add support for UILayoutGuide --- SnapKit.xcodeproj/project.pbxproj | 72 +++---- Source/Constraint.swift | 6 +- Source/ConstraintDSL.swift | 179 ++++++++++++++++++ Source/ConstraintItem.swift | 4 - Source/ConstraintViewDSL.swift | 133 +------------ ...t.swift => UILayoutGuide+Extensions.swift} | 16 +- ...xtensions.swift => UILayoutGuideDSL.swift} | 43 ++--- ...swift => UILayoutSupport+Extensions.swift} | 17 +- ...llerDSL.swift => UILayoutSupportDSL.swift} | 56 +++--- Tests/Tests.swift | 59 +----- 10 files changed, 293 insertions(+), 292 deletions(-) create mode 100644 Source/ConstraintDSL.swift rename Source/{ConstraintLayoutSupport.swift => UILayoutGuide+Extensions.swift} (87%) rename Source/{ConstraintViewController+Extensions.swift => UILayoutGuideDSL.swift} (55%) rename Source/{ConstraintViewController.swift => UILayoutSupport+Extensions.swift} (86%) rename Source/{ConstraintViewControllerDSL.swift => UILayoutSupportDSL.swift} (51%) diff --git a/SnapKit.xcodeproj/project.pbxproj b/SnapKit.xcodeproj/project.pbxproj index 31ba47f..f85712c 100644 --- a/SnapKit.xcodeproj/project.pbxproj +++ b/SnapKit.xcodeproj/project.pbxproj @@ -29,15 +29,9 @@ EE235F791C5785C600C08960 /* ConstraintView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F661C5785C600C08960 /* ConstraintView.swift */; }; EE235F7A1C5785C600C08960 /* ConstraintView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F661C5785C600C08960 /* ConstraintView.swift */; }; EE235F7B1C5785C600C08960 /* ConstraintView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F661C5785C600C08960 /* ConstraintView.swift */; }; - EE235F7C1C5785C600C08960 /* ConstraintViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F671C5785C600C08960 /* ConstraintViewController.swift */; }; - EE235F7D1C5785C600C08960 /* ConstraintViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F671C5785C600C08960 /* ConstraintViewController.swift */; }; - EE235F7E1C5785C600C08960 /* ConstraintViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F671C5785C600C08960 /* ConstraintViewController.swift */; }; EE235F7F1C5785C600C08960 /* ConstraintRelation.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F681C5785C600C08960 /* ConstraintRelation.swift */; }; EE235F801C5785C600C08960 /* ConstraintRelation.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F681C5785C600C08960 /* ConstraintRelation.swift */; }; EE235F811C5785C600C08960 /* ConstraintRelation.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F681C5785C600C08960 /* ConstraintRelation.swift */; }; - EE235F821C5785C600C08960 /* ConstraintLayoutSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F691C5785C600C08960 /* ConstraintLayoutSupport.swift */; }; - EE235F831C5785C600C08960 /* ConstraintLayoutSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F691C5785C600C08960 /* ConstraintLayoutSupport.swift */; }; - EE235F841C5785C600C08960 /* ConstraintLayoutSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F691C5785C600C08960 /* ConstraintLayoutSupport.swift */; }; EE235F851C5785C600C08960 /* ConstraintAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6A1C5785C600C08960 /* ConstraintAttributes.swift */; }; EE235F861C5785C600C08960 /* ConstraintAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6A1C5785C600C08960 /* ConstraintAttributes.swift */; }; EE235F871C5785C600C08960 /* ConstraintAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6A1C5785C600C08960 /* ConstraintAttributes.swift */; }; @@ -86,15 +80,12 @@ EE235FC01C5785DC00C08960 /* ConstraintViewDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBE1C5785DC00C08960 /* ConstraintViewDSL.swift */; }; EE235FC11C5785DC00C08960 /* ConstraintViewDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBE1C5785DC00C08960 /* ConstraintViewDSL.swift */; }; EE235FC21C5785DC00C08960 /* ConstraintViewDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBE1C5785DC00C08960 /* ConstraintViewDSL.swift */; }; - EE235FC31C5785DC00C08960 /* ConstraintViewControllerDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* ConstraintViewControllerDSL.swift */; }; - EE235FC41C5785DC00C08960 /* ConstraintViewControllerDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* ConstraintViewControllerDSL.swift */; }; - EE235FC51C5785DC00C08960 /* ConstraintViewControllerDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* ConstraintViewControllerDSL.swift */; }; + EE235FC31C5785DC00C08960 /* UILayoutSupportDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* UILayoutSupportDSL.swift */; }; + EE235FC41C5785DC00C08960 /* UILayoutSupportDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* UILayoutSupportDSL.swift */; }; + EE235FC51C5785DC00C08960 /* UILayoutSupportDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* UILayoutSupportDSL.swift */; }; EE235FC81C5785E200C08960 /* ConstraintView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FC61C5785E200C08960 /* ConstraintView+Extensions.swift */; }; EE235FC91C5785E200C08960 /* ConstraintView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FC61C5785E200C08960 /* ConstraintView+Extensions.swift */; }; EE235FCA1C5785E200C08960 /* ConstraintView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FC61C5785E200C08960 /* ConstraintView+Extensions.swift */; }; - EE235FCB1C5785E200C08960 /* ConstraintViewController+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FC71C5785E200C08960 /* ConstraintViewController+Extensions.swift */; }; - EE235FCC1C5785E200C08960 /* ConstraintViewController+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FC71C5785E200C08960 /* ConstraintViewController+Extensions.swift */; }; - EE235FCD1C5785E200C08960 /* ConstraintViewController+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FC71C5785E200C08960 /* ConstraintViewController+Extensions.swift */; }; EE4910991B19A40200A54F1F /* SnapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EEBCC9D819CC627D0083B827 /* SnapKit.framework */; }; EE94F6091AC0F10A008767FF /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE94F6081AC0F10A008767FF /* UIKit.framework */; }; EE94F60B1AC0F10F008767FF /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE94F60A1AC0F10F008767FF /* AppKit.framework */; }; @@ -103,6 +94,18 @@ EECDB3931AC0CB52006BBC11 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB36A1AC0C95C006BBC11 /* Tests.swift */; }; EECDB3941AC0CB52006BBC11 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB36A1AC0C95C006BBC11 /* Tests.swift */; }; EECDB39D1AC0CC03006BBC11 /* SnapKit.h in Headers */ = {isa = PBXBuildFile; fileRef = EECDB3661AC0C95C006BBC11 /* SnapKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; + EEF68F9E1D78492400980C26 /* UILayoutGuideDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68F9D1D78492400980C26 /* UILayoutGuideDSL.swift */; }; + EEF68FA61D784A5300980C26 /* ConstraintDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FA51D784A5300980C26 /* ConstraintDSL.swift */; }; + EEF68FAB1D784E3800980C26 /* UILayoutGuideDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68F9D1D78492400980C26 /* UILayoutGuideDSL.swift */; }; + EEF68FAC1D784E3800980C26 /* UILayoutGuideDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68F9D1D78492400980C26 /* UILayoutGuideDSL.swift */; }; + EEF68FAD1D784E3A00980C26 /* ConstraintDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FA51D784A5300980C26 /* ConstraintDSL.swift */; }; + EEF68FAE1D784E3B00980C26 /* ConstraintDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FA51D784A5300980C26 /* ConstraintDSL.swift */; }; + EEF68FB01D784FB100980C26 /* UILayoutGuide+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FAF1D784FB100980C26 /* UILayoutGuide+Extensions.swift */; }; + EEF68FB11D784FB100980C26 /* UILayoutGuide+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FAF1D784FB100980C26 /* UILayoutGuide+Extensions.swift */; }; + EEF68FB21D784FB100980C26 /* UILayoutGuide+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FAF1D784FB100980C26 /* UILayoutGuide+Extensions.swift */; }; + EEF68FB41D784FBA00980C26 /* UILayoutSupport+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FB31D784FBA00980C26 /* UILayoutSupport+Extensions.swift */; }; + EEF68FB51D784FBA00980C26 /* UILayoutSupport+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FB31D784FBA00980C26 /* UILayoutSupport+Extensions.swift */; }; + EEF68FB61D784FBA00980C26 /* UILayoutSupport+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FB31D784FBA00980C26 /* UILayoutSupport+Extensions.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -125,9 +128,7 @@ EE235F641C5785C600C08960 /* ConstraintInsets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintInsets.swift; sourceTree = ""; }; EE235F651C5785C600C08960 /* ConstraintConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintConfig.swift; sourceTree = ""; }; EE235F661C5785C600C08960 /* ConstraintView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintView.swift; sourceTree = ""; }; - EE235F671C5785C600C08960 /* ConstraintViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintViewController.swift; sourceTree = ""; }; EE235F681C5785C600C08960 /* ConstraintRelation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintRelation.swift; sourceTree = ""; }; - EE235F691C5785C600C08960 /* ConstraintLayoutSupport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintLayoutSupport.swift; sourceTree = ""; }; EE235F6A1C5785C600C08960 /* ConstraintAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintAttributes.swift; sourceTree = ""; }; EE235F6B1C5785C600C08960 /* ConstraintItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintItem.swift; sourceTree = ""; }; EE235F6C1C5785C600C08960 /* LayoutConstraint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LayoutConstraint.swift; sourceTree = ""; }; @@ -144,9 +145,8 @@ EE235FAA1C5785D400C08960 /* ConstraintMakerRelatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintMakerRelatable.swift; sourceTree = ""; }; EE235FAB1C5785D400C08960 /* ConstraintMakerExtendable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintMakerExtendable.swift; sourceTree = ""; }; EE235FBE1C5785DC00C08960 /* ConstraintViewDSL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintViewDSL.swift; sourceTree = ""; }; - EE235FBF1C5785DC00C08960 /* ConstraintViewControllerDSL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintViewControllerDSL.swift; sourceTree = ""; }; + EE235FBF1C5785DC00C08960 /* UILayoutSupportDSL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UILayoutSupportDSL.swift; sourceTree = ""; }; EE235FC61C5785E200C08960 /* ConstraintView+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConstraintView+Extensions.swift"; sourceTree = ""; }; - EE235FC71C5785E200C08960 /* ConstraintViewController+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConstraintViewController+Extensions.swift"; sourceTree = ""; }; EE94F6081AC0F10A008767FF /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; EE94F60A1AC0F10F008767FF /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/AppKit.framework; sourceTree = DEVELOPER_DIR; }; EEBCC9D819CC627D0083B827 /* SnapKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SnapKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -157,6 +157,10 @@ EECDB36A1AC0C95C006BBC11 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = ""; }; EECDB37A1AC0C9D4006BBC11 /* SnapKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SnapKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; EECDB3841AC0C9D4006BBC11 /* SnapKit OSX Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SnapKit OSX Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + EEF68F9D1D78492400980C26 /* UILayoutGuideDSL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UILayoutGuideDSL.swift; sourceTree = ""; }; + EEF68FA51D784A5300980C26 /* ConstraintDSL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintDSL.swift; sourceTree = ""; }; + EEF68FAF1D784FB100980C26 /* UILayoutGuide+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UILayoutGuide+Extensions.swift"; sourceTree = ""; }; + EEF68FB31D784FBA00980C26 /* UILayoutSupport+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UILayoutSupport+Extensions.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -237,7 +241,8 @@ isa = PBXGroup; children = ( EE235FC61C5785E200C08960 /* ConstraintView+Extensions.swift */, - EE235FC71C5785E200C08960 /* ConstraintViewController+Extensions.swift */, + EEF68FAF1D784FB100980C26 /* UILayoutGuide+Extensions.swift */, + EEF68FB31D784FBA00980C26 /* UILayoutSupport+Extensions.swift */, ); name = Extensions; sourceTree = ""; @@ -245,8 +250,10 @@ EE235F591C57859200C08960 /* DSLs */ = { isa = PBXGroup; children = ( + EEF68FA51D784A5300980C26 /* ConstraintDSL.swift */, EE235FBE1C5785DC00C08960 /* ConstraintViewDSL.swift */, - EE235FBF1C5785DC00C08960 /* ConstraintViewControllerDSL.swift */, + EEF68F9D1D78492400980C26 /* UILayoutGuideDSL.swift */, + EE235FBF1C5785DC00C08960 /* UILayoutSupportDSL.swift */, ); name = DSLs; sourceTree = ""; @@ -285,9 +292,7 @@ EE235F641C5785C600C08960 /* ConstraintInsets.swift */, EE235F651C5785C600C08960 /* ConstraintConfig.swift */, EE235F661C5785C600C08960 /* ConstraintView.swift */, - EE235F671C5785C600C08960 /* ConstraintViewController.swift */, EE235F681C5785C600C08960 /* ConstraintRelation.swift */, - EE235F691C5785C600C08960 /* ConstraintLayoutSupport.swift */, EE235F6A1C5785C600C08960 /* ConstraintAttributes.swift */, EE235F6B1C5785C600C08960 /* ConstraintItem.swift */, EE235F6C1C5785C600C08960 /* LayoutConstraint.swift */, @@ -591,32 +596,33 @@ buildActionMask = 2147483647; files = ( EE235F741C5785C600C08960 /* ConstraintInsets.swift in Sources */, - EE235F831C5785C600C08960 /* ConstraintLayoutSupport.swift in Sources */, EE235FB01C5785D400C08960 /* ConstraintMakerFinalizable.swift in Sources */, - EE235F7D1C5785C600C08960 /* ConstraintViewController.swift in Sources */, EE235F981C5785CE00C08960 /* ConstraintConstantTarget.swift in Sources */, EE235FC91C5785E200C08960 /* ConstraintView+Extensions.swift in Sources */, EE235FB91C5785D400C08960 /* ConstraintMakerRelatable.swift in Sources */, EE235F861C5785C600C08960 /* ConstraintAttributes.swift in Sources */, EE235FA11C5785CE00C08960 /* ConstraintOffsetTarget.swift in Sources */, + EEF68FAB1D784E3800980C26 /* UILayoutGuideDSL.swift in Sources */, EE235FB61C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */, EE235FAD1C5785D400C08960 /* ConstraintMaker.swift in Sources */, EE235F951C5785CE00C08960 /* ConstraintRelatableTarget.swift in Sources */, EE235FBC1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */, + EEF68FAD1D784E3A00980C26 /* ConstraintDSL.swift in Sources */, EE235F891C5785C600C08960 /* ConstraintItem.swift in Sources */, EE235F9B1C5785CE00C08960 /* ConstraintPriorityTarget.swift in Sources */, + EEF68FB11D784FB100980C26 /* UILayoutGuide+Extensions.swift in Sources */, EE235F771C5785C600C08960 /* ConstraintConfig.swift in Sources */, EE235F6E1C5785C600C08960 /* Constraint.swift in Sources */, EE235F7A1C5785C600C08960 /* ConstraintView.swift in Sources */, EE235FB31C5785D400C08960 /* ConstraintMakerPriortizable.swift in Sources */, - EE235FCC1C5785E200C08960 /* ConstraintViewController+Extensions.swift in Sources */, EE235F8C1C5785C600C08960 /* LayoutConstraint.swift in Sources */, EE235FA41C5785CE00C08960 /* ConstraintInsetTarget.swift in Sources */, EE235F9E1C5785CE00C08960 /* ConstraintMultiplierTarget.swift in Sources */, EE235FC11C5785DC00C08960 /* ConstraintViewDSL.swift in Sources */, EE235F601C5785BC00C08960 /* Debugging.swift in Sources */, - EE235FC41C5785DC00C08960 /* ConstraintViewControllerDSL.swift in Sources */, + EE235FC41C5785DC00C08960 /* UILayoutSupportDSL.swift in Sources */, EE235F801C5785C600C08960 /* ConstraintRelation.swift in Sources */, + EEF68FB51D784FBA00980C26 /* UILayoutSupport+Extensions.swift in Sources */, EE235F711C5785C600C08960 /* ConstraintDescription.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -634,32 +640,33 @@ buildActionMask = 2147483647; files = ( EE235F731C5785C600C08960 /* ConstraintInsets.swift in Sources */, - EE235F821C5785C600C08960 /* ConstraintLayoutSupport.swift in Sources */, EE235FAF1C5785D400C08960 /* ConstraintMakerFinalizable.swift in Sources */, - EE235F7C1C5785C600C08960 /* ConstraintViewController.swift in Sources */, EE235F971C5785CE00C08960 /* ConstraintConstantTarget.swift in Sources */, EE235FC81C5785E200C08960 /* ConstraintView+Extensions.swift in Sources */, EE235FB81C5785D400C08960 /* ConstraintMakerRelatable.swift in Sources */, EE235F851C5785C600C08960 /* ConstraintAttributes.swift in Sources */, EE235FA01C5785CE00C08960 /* ConstraintOffsetTarget.swift in Sources */, + EEF68F9E1D78492400980C26 /* UILayoutGuideDSL.swift in Sources */, EE235FB51C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */, EE235FAC1C5785D400C08960 /* ConstraintMaker.swift in Sources */, EE235F941C5785CE00C08960 /* ConstraintRelatableTarget.swift in Sources */, + EEF68FA61D784A5300980C26 /* ConstraintDSL.swift in Sources */, EE235FBB1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */, EE235F881C5785C600C08960 /* ConstraintItem.swift in Sources */, EE235F9A1C5785CE00C08960 /* ConstraintPriorityTarget.swift in Sources */, + EEF68FB01D784FB100980C26 /* UILayoutGuide+Extensions.swift in Sources */, EE235F761C5785C600C08960 /* ConstraintConfig.swift in Sources */, EE235F6D1C5785C600C08960 /* Constraint.swift in Sources */, EE235F791C5785C600C08960 /* ConstraintView.swift in Sources */, EE235FB21C5785D400C08960 /* ConstraintMakerPriortizable.swift in Sources */, - EE235FCB1C5785E200C08960 /* ConstraintViewController+Extensions.swift in Sources */, EE235F8B1C5785C600C08960 /* LayoutConstraint.swift in Sources */, EE235FA31C5785CE00C08960 /* ConstraintInsetTarget.swift in Sources */, EE235F9D1C5785CE00C08960 /* ConstraintMultiplierTarget.swift in Sources */, EE235FC01C5785DC00C08960 /* ConstraintViewDSL.swift in Sources */, EE235F5F1C5785BC00C08960 /* Debugging.swift in Sources */, - EE235FC31C5785DC00C08960 /* ConstraintViewControllerDSL.swift in Sources */, + EE235FC31C5785DC00C08960 /* UILayoutSupportDSL.swift in Sources */, EE235F7F1C5785C600C08960 /* ConstraintRelation.swift in Sources */, + EEF68FB41D784FBA00980C26 /* UILayoutSupport+Extensions.swift in Sources */, EE235F701C5785C600C08960 /* ConstraintDescription.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -677,32 +684,33 @@ buildActionMask = 2147483647; files = ( EE235F751C5785C600C08960 /* ConstraintInsets.swift in Sources */, - EE235F841C5785C600C08960 /* ConstraintLayoutSupport.swift in Sources */, EE235FB11C5785D400C08960 /* ConstraintMakerFinalizable.swift in Sources */, - EE235F7E1C5785C600C08960 /* ConstraintViewController.swift in Sources */, EE235F991C5785CE00C08960 /* ConstraintConstantTarget.swift in Sources */, EE235FCA1C5785E200C08960 /* ConstraintView+Extensions.swift in Sources */, EE235FBA1C5785D400C08960 /* ConstraintMakerRelatable.swift in Sources */, EE235F871C5785C600C08960 /* ConstraintAttributes.swift in Sources */, EE235FA21C5785CE00C08960 /* ConstraintOffsetTarget.swift in Sources */, + EEF68FAC1D784E3800980C26 /* UILayoutGuideDSL.swift in Sources */, EE235FB71C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */, EE235FAE1C5785D400C08960 /* ConstraintMaker.swift in Sources */, EE235F961C5785CE00C08960 /* ConstraintRelatableTarget.swift in Sources */, EE235FBD1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */, + EEF68FAE1D784E3B00980C26 /* ConstraintDSL.swift in Sources */, EE235F8A1C5785C600C08960 /* ConstraintItem.swift in Sources */, EE235F9C1C5785CE00C08960 /* ConstraintPriorityTarget.swift in Sources */, + EEF68FB21D784FB100980C26 /* UILayoutGuide+Extensions.swift in Sources */, EE235F781C5785C600C08960 /* ConstraintConfig.swift in Sources */, EE235F6F1C5785C600C08960 /* Constraint.swift in Sources */, EE235F7B1C5785C600C08960 /* ConstraintView.swift in Sources */, EE235FB41C5785D400C08960 /* ConstraintMakerPriortizable.swift in Sources */, - EE235FCD1C5785E200C08960 /* ConstraintViewController+Extensions.swift in Sources */, EE235F8D1C5785C600C08960 /* LayoutConstraint.swift in Sources */, EE235FA51C5785CE00C08960 /* ConstraintInsetTarget.swift in Sources */, EE235F9F1C5785CE00C08960 /* ConstraintMultiplierTarget.swift in Sources */, EE235FC21C5785DC00C08960 /* ConstraintViewDSL.swift in Sources */, EE235F611C5785BC00C08960 /* Debugging.swift in Sources */, - EE235FC51C5785DC00C08960 /* ConstraintViewControllerDSL.swift in Sources */, + EE235FC51C5785DC00C08960 /* UILayoutSupportDSL.swift in Sources */, EE235F811C5785C600C08960 /* ConstraintRelation.swift in Sources */, + EEF68FB61D784FBA00980C26 /* UILayoutSupport+Extensions.swift in Sources */, EE235F721C5785C600C08960 /* ConstraintDescription.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Source/Constraint.swift b/Source/Constraint.swift index d0fae6f..e9abd75 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -86,11 +86,7 @@ public class Constraint { let layoutConstant: CGFloat = self.constant.constraintConstantTargetValueFor(layoutAttribute: layoutToAttribute) // get layout to - #if os(iOS) || os(tvOS) - var layoutTo: AnyObject? = self.to.view ?? self.to.layoutSupport - #else - var layoutTo: AnyObject? = self.to.view - #endif + var layoutTo: AnyObject? = self.to.target // use superview if possible if layoutTo == nil && layoutToAttribute != .width && layoutToAttribute != .height { diff --git a/Source/ConstraintDSL.swift b/Source/ConstraintDSL.swift new file mode 100644 index 0000000..837e80b --- /dev/null +++ b/Source/ConstraintDSL.swift @@ -0,0 +1,179 @@ +// +// SnapKit +// +// Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#if os(iOS) || os(tvOS) + import UIKit +#else + import AppKit +#endif + + +public protocol ConstraintDSL { + + var label: String? { get set } + var target: AnyObject? { get } + +} +extension ConstraintDSL { + + public var label: String? { + get { + return objc_getAssociatedObject(self.target, &labelKey) as? String + } + set { + objc_setAssociatedObject(self.target, &labelKey, newValue, .OBJC_ASSOCIATION_COPY_NONATOMIC) + } + } + +} +private var labelKey: UInt8 = 0 + + +public protocol ConstraintAttributesDSL: ConstraintDSL { +} +extension ConstraintAttributesDSL { + + // MARK: Basics + + public var left: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.left) + } + + public var top: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.top) + } + + public var right: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.right) + } + + public var bottom: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.bottom) + } + + public var leading: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.leading) + } + + public var trailing: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.trailing) + } + + public var width: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.width) + } + + public var height: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.height) + } + + public var centerX: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerX) + } + + public var centerY: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerY) + } + + public var edges: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.edges) + } + + public var size: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.size) + } + + public var center: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.center) + } + + // MARK: Baselines + + @available(*, deprecated:0.40.0, message:"Use .lastBaseline instead") + public var baseline: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.lastBaseline) + } + + @available(iOS 8.0, OSX 10.11, *) + public var lastBaseline: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.lastBaseline) + } + + @available(iOS 8.0, OSX 10.11, *) + public var firstBaseline: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.firstBaseline) + } + + // MARK: Margins + + @available(iOS 8.0, *) + public var leftMargin: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.leftMargin) + } + + @available(iOS 8.0, *) + public var topMargin: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.topMargin) + } + + @available(iOS 8.0, *) + public var rightMargin: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.rightMargin) + } + + @available(iOS 8.0, *) + public var bottomMargin: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.bottomMargin) + } + + @available(iOS 8.0, *) + public var leadingMargin: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.leadingMargin) + } + + @available(iOS 8.0, *) + public var trailingMargin: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.trailingMargin) + } + + @available(iOS 8.0, *) + public var centerXWithinMargins: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerXWithinMargins) + } + + @available(iOS 8.0, *) + public var centerYWithinMargins: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerYWithinMargins) + } + + @available(iOS 8.0, *) + public var margins: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.margins) + } + + @available(iOS 8.0, *) + public var centerWithinMargins: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerWithinMargins) + } + +} diff --git a/Source/ConstraintItem.swift b/Source/ConstraintItem.swift index 83733b5..a9477da 100644 --- a/Source/ConstraintItem.swift +++ b/Source/ConstraintItem.swift @@ -42,10 +42,6 @@ public class ConstraintItem: Equatable { return self.target as? ConstraintView } - internal var layoutSupport: ConstraintLayoutSupport? { - return self.target as? ConstraintLayoutSupport - } - } public func ==(lhs: ConstraintItem, rhs: ConstraintItem) -> Bool { diff --git a/Source/ConstraintViewDSL.swift b/Source/ConstraintViewDSL.swift index ef3d6b1..a782ea9 100644 --- a/Source/ConstraintViewDSL.swift +++ b/Source/ConstraintViewDSL.swift @@ -28,124 +28,7 @@ #endif -public struct ConstraintViewDSL { - - public var left: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.left) - } - - public var top: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.top) - } - - public var right: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.right) - } - - public var bottom: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.bottom) - } - - public var leading: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.leading) - } - - public var trailing: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.trailing) - } - - public var width: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.width) - } - - public var height: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.height) - } - - public var centerX: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.centerX) - } - - public var centerY: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.centerY) - } - - @available(*, deprecated:0.40.0, message:"Use .lastBaseline instead") - public var baseline: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.lastBaseline) - } - - @available(iOS 8.0, OSX 10.11, *) - public var lastBaseline: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.lastBaseline) - } - - @available(iOS 8.0, OSX 10.11, *) - public var firstBaseline: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.firstBaseline) - } - - @available(iOS 8.0, *) - public var leftMargin: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.leftMargin) - } - - @available(iOS 8.0, *) - public var topMargin: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.topMargin) - } - - @available(iOS 8.0, *) - public var rightMargin: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.rightMargin) - } - - @available(iOS 8.0, *) - public var bottomMargin: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.bottomMargin) - } - - @available(iOS 8.0, *) - public var leadingMargin: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.leadingMargin) - } - - @available(iOS 8.0, *) - public var trailingMargin: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.trailingMargin) - } - - @available(iOS 8.0, *) - public var centerXWithinMargins: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.centerXWithinMargins) - } - - @available(iOS 8.0, *) - public var centerYWithinMargins: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.centerYWithinMargins) - } - - public var edges: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.edges) - } - - public var size: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.size) - } - - public var center: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.center) - } - - @available(iOS 8.0, *) - public var margins: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.margins) - } - - @available(iOS 8.0, *) - public var centerWithinMargins: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.centerWithinMargins) - } +public struct ConstraintViewDSL: ConstraintAttributesDSL { @discardableResult public func prepareConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] { @@ -168,14 +51,7 @@ public struct ConstraintViewDSL { ConstraintMaker.removeConstraints(view: self.view) } - public var label: String? { - get { - return objc_getAssociatedObject(self.view, &labelKey) as? String - } - set { - objc_setAssociatedObject(self.view, &labelKey, newValue, .OBJC_ASSOCIATION_COPY_NONATOMIC) - } - } + public var contentHuggingHorizontalPriority: Float { get { @@ -213,6 +89,10 @@ public struct ConstraintViewDSL { } } + public var target: AnyObject? { + return self.view + } + internal let view: ConstraintView internal init(view: ConstraintView) { @@ -235,5 +115,4 @@ public struct ConstraintViewDSL { } } -private var labelKey: UInt8 = 0 private var layoutConstraintsKey: UInt8 = 0 diff --git a/Source/ConstraintLayoutSupport.swift b/Source/UILayoutGuide+Extensions.swift similarity index 87% rename from Source/ConstraintLayoutSupport.swift rename to Source/UILayoutGuide+Extensions.swift index 60f4aff..bd8c2a5 100644 --- a/Source/ConstraintLayoutSupport.swift +++ b/Source/UILayoutGuide+Extensions.swift @@ -23,8 +23,14 @@ #if os(iOS) || os(tvOS) import UIKit - internal typealias ConstraintLayoutSupport = UILayoutSupport -#else - import AppKit - internal class ConstraintLayoutSupport { } -#endif \ No newline at end of file +#endif + + +@available(iOS 9.0, *) +public extension UILayoutGuide { + + public var snp: UILayoutGuideDSL { + return UILayoutGuideDSL(guide: self) + } + +} diff --git a/Source/ConstraintViewController+Extensions.swift b/Source/UILayoutGuideDSL.swift similarity index 55% rename from Source/ConstraintViewController+Extensions.swift rename to Source/UILayoutGuideDSL.swift index 4324b13..588c5f1 100644 --- a/Source/ConstraintViewController+Extensions.swift +++ b/Source/UILayoutGuideDSL.swift @@ -23,34 +23,23 @@ #if os(iOS) || os(tvOS) import UIKit +#else + import AppKit +#endif - public extension ConstraintViewController { - - @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") - public var topLayoutGuideTop: ConstraintItem { - return self.snp.topLayoutGuideTop - } - - @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") - public var topLayoutGuideBottom: ConstraintItem { - return self.snp.topLayoutGuideBottom - } - - @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") - public var bottomLayoutGuideTop: ConstraintItem { - return self.snp.bottomLayoutGuideTop - } - - @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") - public var bottomLayoutGuideBottom: ConstraintItem { - return self.snp.bottomLayoutGuideBottom - } - - public var snp: ConstraintViewControllerDSL { - return ConstraintViewControllerDSL(viewController: self) - } +@available(iOS 9.0, *) +public struct UILayoutGuideDSL: ConstraintAttributesDSL { + + public var target: AnyObject? { + return self.guide + } + + internal let guide: UILayoutGuide + + internal init(guide: UILayoutGuide) { + self.guide = guide } - -#endif + +} diff --git a/Source/ConstraintViewController.swift b/Source/UILayoutSupport+Extensions.swift similarity index 86% rename from Source/ConstraintViewController.swift rename to Source/UILayoutSupport+Extensions.swift index 9346efa..eac30f7 100644 --- a/Source/ConstraintViewController.swift +++ b/Source/UILayoutSupport+Extensions.swift @@ -23,13 +23,14 @@ #if os(iOS) || os(tvOS) import UIKit -#else - import AppKit #endif - -#if os(iOS) || os(tvOS) - public typealias ConstraintViewController = UIViewController -#else - public typealias ConstraintViewController = NSViewController -#endif + +@available(iOS 8.0, *) +public extension UILayoutSupport { + + public var snp: UILayoutSupportDSL { + return UILayoutSupportDSL(support: self) + } + +} diff --git a/Source/ConstraintViewControllerDSL.swift b/Source/UILayoutSupportDSL.swift similarity index 51% rename from Source/ConstraintViewControllerDSL.swift rename to Source/UILayoutSupportDSL.swift index 137b7b5..0180d2f 100644 --- a/Source/ConstraintViewControllerDSL.swift +++ b/Source/UILayoutSupportDSL.swift @@ -23,36 +23,34 @@ #if os(iOS) || os(tvOS) import UIKit +#else + import AppKit +#endif - public struct ConstraintViewControllerDSL { - - @available(iOS 8.0, *) - public var topLayoutGuideTop: ConstraintItem { - return ConstraintItem(target: self.viewController.topLayoutGuide, attributes: ConstraintAttributes.top) - } - - @available(iOS 8.0, *) - public var topLayoutGuideBottom: ConstraintItem { - return ConstraintItem(target: self.viewController.topLayoutGuide, attributes: ConstraintAttributes.bottom) - } - - @available(iOS 8.0, *) - public var bottomLayoutGuideTop: ConstraintItem { - return ConstraintItem(target: self.viewController.bottomLayoutGuide, attributes: ConstraintAttributes.top) - } - - @available(iOS 8.0, *) - public var bottomLayoutGuideBottom: ConstraintItem { - return ConstraintItem(target: self.viewController.bottomLayoutGuide, attributes: ConstraintAttributes.bottom) - } - - internal let viewController: ConstraintViewController - - internal init(viewController: ConstraintViewController) { - self.viewController = viewController - } +@available(iOS 8.0, *) +public struct UILayoutSupportDSL: ConstraintDSL { + + public var target: AnyObject? { + return self.support + } + + internal let support: UILayoutSupport + + internal init(support: UILayoutSupport) { + self.support = support } - -#endif + + public var top: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.top) + } + + public var bottom: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.bottom) + } + + public var height: ConstraintItem { + return ConstraintItem(target: self.target, attributes: ConstraintAttributes.height) + } +} diff --git a/Tests/Tests.swift b/Tests/Tests.swift index fef7af9..4eebb8f 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -37,10 +37,12 @@ class SnapKitTests: XCTestCase { vc.view.addSubview(self.container) self.container.snp.makeConstraints { (make) -> Void in - make.top.equalTo(vc.snp.topLayoutGuideBottom) - make.bottom.equalTo(vc.snp.bottomLayoutGuideTop) + make.top.equalTo(vc.topLayoutGuide.snp.bottom) + make.bottom.equalTo(vc.bottomLayoutGuide.snp.top) } + print(vc.view.snp_constraints) + XCTAssertEqual(vc.view.snp_constraints.count, 6, "Should have 6 constraints installed") #endif } @@ -318,58 +320,5 @@ class SnapKitTests: XCTestCase { let constraints = container.snp_constraints as! [NSLayoutConstraint] XCTAssertEqual(constraints[0].identifier, identifier, "Identifier should be 'Test'") } -// -//// func testSuperviewConstraints() { -//// let view = View() -//// -//// container.addSubview(view) -//// -//// view.snp.makeConstraints { (make) -> Void in -//// make.top.equalToSuperview().inset(10) -//// make.bottom.equalToSuperview().inset(10) -//// } -//// -//// XCTAssertEqual(container.snp_constraints.count, 2, "Should have 2 constraints") -//// -//// let constraints = container.snp_constraints as! [NSLayoutConstraint] -//// -//// XCTAssertEqual(constraints[0].firstAttribute, NSLayoutAttribute.top, "Should be top") -//// XCTAssertEqual(constraints[1].firstAttribute, NSLayoutAttribute.bottom, "Should be bottom") -//// -//// XCTAssertEqual(constraints[0].secondAttribute, NSLayoutAttribute.top, "Should be top") -//// XCTAssertEqual(constraints[1].secondAttribute, NSLayoutAttribute.bottom, "Should be bottom") -//// -//// XCTAssertEqual(constraints[0].firstItem as? View, view, "Should be added subview") -//// XCTAssertEqual(constraints[1].firstItem as? View, view, "Should be added subview") -//// -//// XCTAssertEqual(constraints[0].secondItem as? View, container, "Should be containerView") -//// XCTAssertEqual(constraints[1].secondItem as? View, container, "Should be containerView") -//// -//// XCTAssertEqual(constraints[0].constant, 10, "Should be 10") -//// XCTAssertEqual(constraints[1].constant, -10, "Should be 10") -//// } -// -//// func testNativeConstraints() { -//// let view = View() -//// -//// container.addSubview(view) -//// -//// var topNativeConstraints: [LayoutConstraint]! -//// var topNativeConstraint: LayoutConstraint? -//// var sizeNativeConstraints: [LayoutConstraint]! -//// view.snp_makeConstraints { (make) -> Void in -//// let topConstraint = make.top.equalToSuperview().inset(10).constraint -//// topNativeConstraints = topConstraint.layoutConstraints -//// topNativeConstraint = topConstraint.layoutConstraints.first -//// let sizeConstraints = make.size.equalTo(50).constraint -//// sizeNativeConstraints = sizeConstraints.layoutConstraints -//// } -//// -//// XCTAssertEqual(topNativeConstraints.count, 1, "make.top should creates one native constraint") -//// XCTAssertEqual(topNativeConstraint?.constant, 10, "topNativeConstraint.constant is set to 10") -//// XCTAssertEqual(sizeNativeConstraints.count, 2, "make.tosize should create two native constraint") -//// XCTAssertEqual(sizeNativeConstraints[0].constant, 50, "sizeNativeConstraints should set size[0] to 50") -//// XCTAssertEqual(sizeNativeConstraints[1].constant, 50, "sizeNativeConstraints should set size[1] to 50") -//// } }