From 7ba532d5972254aaf22d214f981193d5b42204dc Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Tue, 26 Jan 2016 23:49:04 +1300 Subject: [PATCH 01/58] Major overhaul --- SnapKit.xcodeproj/project.pbxproj | 384 +++++++++---- Source/Constraint.swift | 512 ++++++------------ Source/ConstraintAttributes.swift | 81 +-- .../{SnapKit.swift => ConstraintConfig.swift} | 23 +- Source/ConstraintConstantTarget.swift | 148 +++++ Source/ConstraintDescription.swift | 506 ++--------------- ...sets.swift => ConstraintInsetTarget.swift} | 38 +- Source/ConstraintInsets.swift | 35 ++ Source/ConstraintItem.swift | 57 +- ...on.swift => ConstraintLayoutSupport.swift} | 20 +- Source/ConstraintMaker.swift | 221 ++++---- Source/ConstraintMakerEditable.swift | 71 +++ Source/ConstraintMakerExtendable.swift | 157 ++++++ Source/ConstraintMakerFinalizable.swift | 43 ++ ...wift => ConstraintMakerPriortizable.swift} | 43 +- Source/ConstraintMakerRelatable.swift | 82 +++ Source/ConstraintMultiplierTarget.swift | 79 +++ Source/ConstraintOffsetTarget.swift | 47 ++ Source/ConstraintPriorityTarget.swift | 79 +++ Source/ConstraintRelatableTarget.swift | 62 +++ Source/ConstraintRelation.swift | 26 +- Source/ConstraintView+Extensions.swift | 137 +++++ Source/ConstraintView.swift | 35 ++ .../ConstraintViewController+Extensions.swift | 56 ++ Source/ConstraintViewController.swift | 35 ++ Source/ConstraintViewControllerDSL.swift | 58 ++ Source/ConstraintViewDSL.swift | 196 +++++++ Source/Debugging.swift | 123 ++--- Source/LayoutConstraint.swift | 45 +- Source/View+SnapKit.swift | 183 ------- Tests/Tests.swift | 198 ------- 31 files changed, 2109 insertions(+), 1671 deletions(-) rename Source/{SnapKit.swift => ConstraintConfig.swift} (68%) create mode 100644 Source/ConstraintConstantTarget.swift rename Source/{EdgeInsets.swift => ConstraintInsetTarget.swift} (62%) create mode 100644 Source/ConstraintInsets.swift rename Source/{SourceLocation.swift => ConstraintLayoutSupport.swift} (85%) create mode 100644 Source/ConstraintMakerEditable.swift create mode 100644 Source/ConstraintMakerExtendable.swift create mode 100644 Source/ConstraintMakerFinalizable.swift rename Source/{ViewController+SnapKit.swift => ConstraintMakerPriortizable.swift} (56%) create mode 100644 Source/ConstraintMakerRelatable.swift create mode 100644 Source/ConstraintMultiplierTarget.swift create mode 100644 Source/ConstraintOffsetTarget.swift create mode 100644 Source/ConstraintPriorityTarget.swift create mode 100644 Source/ConstraintRelatableTarget.swift create mode 100644 Source/ConstraintView+Extensions.swift create mode 100644 Source/ConstraintView.swift create mode 100644 Source/ConstraintViewController+Extensions.swift create mode 100644 Source/ConstraintViewController.swift create mode 100644 Source/ConstraintViewControllerDSL.swift create mode 100644 Source/ConstraintViewDSL.swift delete mode 100644 Source/View+SnapKit.swift diff --git a/SnapKit.xcodeproj/project.pbxproj b/SnapKit.xcodeproj/project.pbxproj index 040e000..920c9cd 100644 --- a/SnapKit.xcodeproj/project.pbxproj +++ b/SnapKit.xcodeproj/project.pbxproj @@ -8,55 +8,101 @@ /* Begin PBXBuildFile section */ 537DCE9B1C35CD4100B5B899 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 537DCE9A1C35CD4100B5B899 /* UIKit.framework */; }; - 537DCE9C1C35CD9A00B5B899 /* Constraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB35E1AC0C95C006BBC11 /* Constraint.swift */; }; - 537DCE9D1C35CDA300B5B899 /* SnapKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEFCF32E1AD926AE00A425FA /* SnapKit.swift */; }; - 537DCE9E1C35CDAA00B5B899 /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEFCF32B1AD910B900A425FA /* Debugging.swift */; }; - 537DCE9F1C35CDB700B5B899 /* ConstraintItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3601AC0C95C006BBC11 /* ConstraintItem.swift */; }; 537DCEA01C35CDF800B5B899 /* SnapKit.h in Headers */ = {isa = PBXBuildFile; fileRef = EECDB3661AC0C95C006BBC11 /* SnapKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 537DCEA11C35CE0000B5B899 /* ConstraintDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEFCF3311AD9432400A425FA /* ConstraintDescription.swift */; }; - 537DCEA21C35CE0500B5B899 /* ConstraintMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3611AC0C95C006BBC11 /* ConstraintMaker.swift */; }; - 537DCEA31C35CE0900B5B899 /* View+SnapKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3671AC0C95C006BBC11 /* View+SnapKit.swift */; }; - 537DCEA41C35CE1500B5B899 /* ViewController+SnapKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4910971B19A26000A54F1F /* ViewController+SnapKit.swift */; }; - 537DCEA51C35CE1B00B5B899 /* EdgeInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3631AC0C95C006BBC11 /* EdgeInsets.swift */; }; - 537DCEA61C35CE2000B5B899 /* LayoutConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3651AC0C95C006BBC11 /* LayoutConstraint.swift */; }; - 537DCEA81C35CE3800B5B899 /* ConstraintRelation.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3621AC0C95C006BBC11 /* ConstraintRelation.swift */; }; - 537DCEA91C35CE3E00B5B899 /* ConstraintAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB35F1AC0C95C006BBC11 /* ConstraintAttributes.swift */; }; - 537DCEAA1C35CE4800B5B899 /* SourceLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779230431BCB6FC30027CF5F /* SourceLocation.swift */; }; 537DCEB41C35D90A00B5B899 /* SnapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 537DCE921C35CC8800B5B899 /* SnapKit.framework */; }; 537DCEBA1C35DA9700B5B899 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB36A1AC0C95C006BBC11 /* Tests.swift */; }; - 779230441BCB6FC30027CF5F /* SourceLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779230431BCB6FC30027CF5F /* SourceLocation.swift */; }; - 779230451BCB6FC30027CF5F /* SourceLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779230431BCB6FC30027CF5F /* SourceLocation.swift */; }; - EE4910981B19A26000A54F1F /* ViewController+SnapKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4910971B19A26000A54F1F /* ViewController+SnapKit.swift */; }; + EE235F5F1C5785BC00C08960 /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F5E1C5785BC00C08960 /* Debugging.swift */; }; + EE235F601C5785BC00C08960 /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F5E1C5785BC00C08960 /* Debugging.swift */; }; + EE235F611C5785BC00C08960 /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F5E1C5785BC00C08960 /* Debugging.swift */; }; + EE235F6D1C5785C600C08960 /* Constraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F621C5785C600C08960 /* Constraint.swift */; }; + EE235F6E1C5785C600C08960 /* Constraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F621C5785C600C08960 /* Constraint.swift */; }; + EE235F6F1C5785C600C08960 /* Constraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F621C5785C600C08960 /* Constraint.swift */; }; + EE235F701C5785C600C08960 /* ConstraintDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F631C5785C600C08960 /* ConstraintDescription.swift */; }; + EE235F711C5785C600C08960 /* ConstraintDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F631C5785C600C08960 /* ConstraintDescription.swift */; }; + EE235F721C5785C600C08960 /* ConstraintDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F631C5785C600C08960 /* ConstraintDescription.swift */; }; + EE235F731C5785C600C08960 /* ConstraintInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F641C5785C600C08960 /* ConstraintInsets.swift */; }; + EE235F741C5785C600C08960 /* ConstraintInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F641C5785C600C08960 /* ConstraintInsets.swift */; }; + EE235F751C5785C600C08960 /* ConstraintInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F641C5785C600C08960 /* ConstraintInsets.swift */; }; + EE235F761C5785C600C08960 /* ConstraintConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F651C5785C600C08960 /* ConstraintConfig.swift */; }; + EE235F771C5785C600C08960 /* ConstraintConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F651C5785C600C08960 /* ConstraintConfig.swift */; }; + EE235F781C5785C600C08960 /* ConstraintConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F651C5785C600C08960 /* ConstraintConfig.swift */; }; + 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 */; }; + EE235F881C5785C600C08960 /* ConstraintItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6B1C5785C600C08960 /* ConstraintItem.swift */; }; + EE235F891C5785C600C08960 /* ConstraintItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6B1C5785C600C08960 /* ConstraintItem.swift */; }; + EE235F8A1C5785C600C08960 /* ConstraintItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6B1C5785C600C08960 /* ConstraintItem.swift */; }; + EE235F8B1C5785C600C08960 /* LayoutConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6C1C5785C600C08960 /* LayoutConstraint.swift */; }; + EE235F8C1C5785C600C08960 /* LayoutConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6C1C5785C600C08960 /* LayoutConstraint.swift */; }; + EE235F8D1C5785C600C08960 /* LayoutConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6C1C5785C600C08960 /* LayoutConstraint.swift */; }; + EE235F941C5785CE00C08960 /* ConstraintRelatableTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F8E1C5785CE00C08960 /* ConstraintRelatableTarget.swift */; }; + EE235F951C5785CE00C08960 /* ConstraintRelatableTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F8E1C5785CE00C08960 /* ConstraintRelatableTarget.swift */; }; + EE235F961C5785CE00C08960 /* ConstraintRelatableTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F8E1C5785CE00C08960 /* ConstraintRelatableTarget.swift */; }; + EE235F971C5785CE00C08960 /* ConstraintConstantTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F8F1C5785CE00C08960 /* ConstraintConstantTarget.swift */; }; + EE235F981C5785CE00C08960 /* ConstraintConstantTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F8F1C5785CE00C08960 /* ConstraintConstantTarget.swift */; }; + EE235F991C5785CE00C08960 /* ConstraintConstantTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F8F1C5785CE00C08960 /* ConstraintConstantTarget.swift */; }; + EE235F9A1C5785CE00C08960 /* ConstraintPriorityTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F901C5785CE00C08960 /* ConstraintPriorityTarget.swift */; }; + EE235F9B1C5785CE00C08960 /* ConstraintPriorityTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F901C5785CE00C08960 /* ConstraintPriorityTarget.swift */; }; + EE235F9C1C5785CE00C08960 /* ConstraintPriorityTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F901C5785CE00C08960 /* ConstraintPriorityTarget.swift */; }; + EE235F9D1C5785CE00C08960 /* ConstraintMultiplierTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F911C5785CE00C08960 /* ConstraintMultiplierTarget.swift */; }; + EE235F9E1C5785CE00C08960 /* ConstraintMultiplierTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F911C5785CE00C08960 /* ConstraintMultiplierTarget.swift */; }; + EE235F9F1C5785CE00C08960 /* ConstraintMultiplierTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F911C5785CE00C08960 /* ConstraintMultiplierTarget.swift */; }; + EE235FA01C5785CE00C08960 /* ConstraintOffsetTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F921C5785CE00C08960 /* ConstraintOffsetTarget.swift */; }; + EE235FA11C5785CE00C08960 /* ConstraintOffsetTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F921C5785CE00C08960 /* ConstraintOffsetTarget.swift */; }; + EE235FA21C5785CE00C08960 /* ConstraintOffsetTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F921C5785CE00C08960 /* ConstraintOffsetTarget.swift */; }; + EE235FA31C5785CE00C08960 /* ConstraintInsetTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F931C5785CE00C08960 /* ConstraintInsetTarget.swift */; }; + EE235FA41C5785CE00C08960 /* ConstraintInsetTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F931C5785CE00C08960 /* ConstraintInsetTarget.swift */; }; + EE235FA51C5785CE00C08960 /* ConstraintInsetTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F931C5785CE00C08960 /* ConstraintInsetTarget.swift */; }; + EE235FAC1C5785D400C08960 /* ConstraintMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA61C5785D400C08960 /* ConstraintMaker.swift */; }; + EE235FAD1C5785D400C08960 /* ConstraintMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA61C5785D400C08960 /* ConstraintMaker.swift */; }; + EE235FAE1C5785D400C08960 /* ConstraintMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA61C5785D400C08960 /* ConstraintMaker.swift */; }; + EE235FAF1C5785D400C08960 /* ConstraintMakerFinalizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA71C5785D400C08960 /* ConstraintMakerFinalizable.swift */; }; + EE235FB01C5785D400C08960 /* ConstraintMakerFinalizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA71C5785D400C08960 /* ConstraintMakerFinalizable.swift */; }; + EE235FB11C5785D400C08960 /* ConstraintMakerFinalizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA71C5785D400C08960 /* ConstraintMakerFinalizable.swift */; }; + EE235FB21C5785D400C08960 /* ConstraintMakerPriortizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA81C5785D400C08960 /* ConstraintMakerPriortizable.swift */; }; + EE235FB31C5785D400C08960 /* ConstraintMakerPriortizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA81C5785D400C08960 /* ConstraintMakerPriortizable.swift */; }; + EE235FB41C5785D400C08960 /* ConstraintMakerPriortizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA81C5785D400C08960 /* ConstraintMakerPriortizable.swift */; }; + EE235FB51C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA91C5785D400C08960 /* ConstraintMakerEditable.swift */; }; + EE235FB61C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA91C5785D400C08960 /* ConstraintMakerEditable.swift */; }; + EE235FB71C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA91C5785D400C08960 /* ConstraintMakerEditable.swift */; }; + EE235FB81C5785D400C08960 /* ConstraintMakerRelatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FAA1C5785D400C08960 /* ConstraintMakerRelatable.swift */; }; + EE235FB91C5785D400C08960 /* ConstraintMakerRelatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FAA1C5785D400C08960 /* ConstraintMakerRelatable.swift */; }; + EE235FBA1C5785D400C08960 /* ConstraintMakerRelatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FAA1C5785D400C08960 /* ConstraintMakerRelatable.swift */; }; + EE235FBB1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FAB1C5785D400C08960 /* ConstraintMakerExtendable.swift */; }; + EE235FBC1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FAB1C5785D400C08960 /* ConstraintMakerExtendable.swift */; }; + EE235FBD1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FAB1C5785D400C08960 /* ConstraintMakerExtendable.swift */; }; + 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 */; }; + 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 */; }; EE94F6111AC0F146008767FF /* SnapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EECDB37A1AC0C9D4006BBC11 /* SnapKit.framework */; }; - EECDB36C1AC0C9A6006BBC11 /* Constraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB35E1AC0C95C006BBC11 /* Constraint.swift */; }; - EECDB36D1AC0C9A6006BBC11 /* ConstraintAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB35F1AC0C95C006BBC11 /* ConstraintAttributes.swift */; }; - EECDB36E1AC0C9A6006BBC11 /* ConstraintItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3601AC0C95C006BBC11 /* ConstraintItem.swift */; }; - EECDB36F1AC0C9A6006BBC11 /* ConstraintMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3611AC0C95C006BBC11 /* ConstraintMaker.swift */; }; - EECDB3701AC0C9A6006BBC11 /* ConstraintRelation.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3621AC0C95C006BBC11 /* ConstraintRelation.swift */; }; - EECDB3711AC0C9A6006BBC11 /* EdgeInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3631AC0C95C006BBC11 /* EdgeInsets.swift */; }; - EECDB3721AC0C9A6006BBC11 /* LayoutConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3651AC0C95C006BBC11 /* LayoutConstraint.swift */; }; - EECDB3731AC0C9A6006BBC11 /* View+SnapKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3671AC0C95C006BBC11 /* View+SnapKit.swift */; }; EECDB3741AC0C9B6006BBC11 /* SnapKit.h in Headers */ = {isa = PBXBuildFile; fileRef = EECDB3661AC0C95C006BBC11 /* SnapKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; EECDB3931AC0CB52006BBC11 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB36A1AC0C95C006BBC11 /* Tests.swift */; }; EECDB3941AC0CB52006BBC11 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB36A1AC0C95C006BBC11 /* Tests.swift */; }; - EECDB3951AC0CBFF006BBC11 /* Constraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB35E1AC0C95C006BBC11 /* Constraint.swift */; }; - EECDB3961AC0CBFF006BBC11 /* ConstraintAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB35F1AC0C95C006BBC11 /* ConstraintAttributes.swift */; }; - EECDB3971AC0CBFF006BBC11 /* ConstraintItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3601AC0C95C006BBC11 /* ConstraintItem.swift */; }; - EECDB3981AC0CBFF006BBC11 /* ConstraintMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3611AC0C95C006BBC11 /* ConstraintMaker.swift */; }; - EECDB3991AC0CBFF006BBC11 /* ConstraintRelation.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3621AC0C95C006BBC11 /* ConstraintRelation.swift */; }; - EECDB39A1AC0CBFF006BBC11 /* EdgeInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3631AC0C95C006BBC11 /* EdgeInsets.swift */; }; - EECDB39B1AC0CBFF006BBC11 /* LayoutConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3651AC0C95C006BBC11 /* LayoutConstraint.swift */; }; - EECDB39C1AC0CBFF006BBC11 /* View+SnapKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB3671AC0C95C006BBC11 /* View+SnapKit.swift */; }; EECDB39D1AC0CC03006BBC11 /* SnapKit.h in Headers */ = {isa = PBXBuildFile; fileRef = EECDB3661AC0C95C006BBC11 /* SnapKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; - EEFCF32C1AD910B900A425FA /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEFCF32B1AD910B900A425FA /* Debugging.swift */; }; - EEFCF32D1AD9250C00A425FA /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEFCF32B1AD910B900A425FA /* Debugging.swift */; }; - EEFCF32F1AD926AE00A425FA /* SnapKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEFCF32E1AD926AE00A425FA /* SnapKit.swift */; }; - EEFCF3301AD92C2200A425FA /* SnapKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEFCF32E1AD926AE00A425FA /* SnapKit.swift */; }; - EEFCF3321AD9432400A425FA /* ConstraintDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEFCF3311AD9432400A425FA /* ConstraintDescription.swift */; }; - EEFCF3331AD9432400A425FA /* ConstraintDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEFCF3311AD9432400A425FA /* ConstraintDescription.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -73,29 +119,44 @@ 537DCE921C35CC8800B5B899 /* SnapKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SnapKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 537DCE9A1C35CD4100B5B899 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.1.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; 537DCEAF1C35D90A00B5B899 /* SnapKit tvOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SnapKit tvOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - 779230431BCB6FC30027CF5F /* SourceLocation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SourceLocation.swift; sourceTree = ""; }; - EE4910971B19A26000A54F1F /* ViewController+SnapKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ViewController+SnapKit.swift"; sourceTree = ""; }; + EE235F5E1C5785BC00C08960 /* Debugging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Debugging.swift; sourceTree = ""; }; + EE235F621C5785C600C08960 /* Constraint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constraint.swift; sourceTree = ""; }; + EE235F631C5785C600C08960 /* ConstraintDescription.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintDescription.swift; sourceTree = ""; }; + 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 = ""; }; + EE235F8E1C5785CE00C08960 /* ConstraintRelatableTarget.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintRelatableTarget.swift; sourceTree = ""; }; + EE235F8F1C5785CE00C08960 /* ConstraintConstantTarget.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintConstantTarget.swift; sourceTree = ""; }; + EE235F901C5785CE00C08960 /* ConstraintPriorityTarget.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintPriorityTarget.swift; sourceTree = ""; }; + EE235F911C5785CE00C08960 /* ConstraintMultiplierTarget.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintMultiplierTarget.swift; sourceTree = ""; }; + EE235F921C5785CE00C08960 /* ConstraintOffsetTarget.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintOffsetTarget.swift; sourceTree = ""; }; + EE235F931C5785CE00C08960 /* ConstraintInsetTarget.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintInsetTarget.swift; sourceTree = ""; }; + EE235FA61C5785D400C08960 /* ConstraintMaker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintMaker.swift; sourceTree = ""; }; + EE235FA71C5785D400C08960 /* ConstraintMakerFinalizable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintMakerFinalizable.swift; sourceTree = ""; }; + EE235FA81C5785D400C08960 /* ConstraintMakerPriortizable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintMakerPriortizable.swift; sourceTree = ""; }; + EE235FA91C5785D400C08960 /* ConstraintMakerEditable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintMakerEditable.swift; sourceTree = ""; }; + 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 = ""; }; + 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; }; EEBCC9E219CC627E0083B827 /* SnapKit iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SnapKit iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - EECDB35E1AC0C95C006BBC11 /* Constraint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constraint.swift; sourceTree = ""; }; - EECDB35F1AC0C95C006BBC11 /* ConstraintAttributes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstraintAttributes.swift; sourceTree = ""; }; - EECDB3601AC0C95C006BBC11 /* ConstraintItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstraintItem.swift; sourceTree = ""; }; - EECDB3611AC0C95C006BBC11 /* ConstraintMaker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstraintMaker.swift; sourceTree = ""; }; - EECDB3621AC0C95C006BBC11 /* ConstraintRelation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstraintRelation.swift; sourceTree = ""; }; - EECDB3631AC0C95C006BBC11 /* EdgeInsets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EdgeInsets.swift; sourceTree = ""; }; EECDB3641AC0C95C006BBC11 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - EECDB3651AC0C95C006BBC11 /* LayoutConstraint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutConstraint.swift; sourceTree = ""; }; EECDB3661AC0C95C006BBC11 /* SnapKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SnapKit.h; sourceTree = ""; }; - EECDB3671AC0C95C006BBC11 /* View+SnapKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+SnapKit.swift"; sourceTree = ""; }; EECDB3691AC0C95C006BBC11 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 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; }; - EEFCF32B1AD910B900A425FA /* Debugging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Debugging.swift; sourceTree = ""; }; - EEFCF32E1AD926AE00A425FA /* SnapKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnapKit.swift; sourceTree = ""; }; - EEFCF3311AD9432400A425FA /* ConstraintDescription.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintDescription.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -172,6 +233,76 @@ name = Products; sourceTree = ""; }; + EE235F581C57858700C08960 /* Extensions */ = { + isa = PBXGroup; + children = ( + EE235FC61C5785E200C08960 /* ConstraintView+Extensions.swift */, + EE235FC71C5785E200C08960 /* ConstraintViewController+Extensions.swift */, + ); + name = Extensions; + sourceTree = ""; + }; + EE235F591C57859200C08960 /* DSLs */ = { + isa = PBXGroup; + children = ( + EE235FBE1C5785DC00C08960 /* ConstraintViewDSL.swift */, + EE235FBF1C5785DC00C08960 /* ConstraintViewControllerDSL.swift */, + ); + name = DSLs; + sourceTree = ""; + }; + EE235F5A1C57859900C08960 /* Maker */ = { + isa = PBXGroup; + children = ( + EE235FA61C5785D400C08960 /* ConstraintMaker.swift */, + EE235FA71C5785D400C08960 /* ConstraintMakerFinalizable.swift */, + EE235FA81C5785D400C08960 /* ConstraintMakerPriortizable.swift */, + EE235FA91C5785D400C08960 /* ConstraintMakerEditable.swift */, + EE235FAA1C5785D400C08960 /* ConstraintMakerRelatable.swift */, + EE235FAB1C5785D400C08960 /* ConstraintMakerExtendable.swift */, + ); + name = Maker; + sourceTree = ""; + }; + EE235F5B1C57859E00C08960 /* Targets */ = { + isa = PBXGroup; + children = ( + EE235F8E1C5785CE00C08960 /* ConstraintRelatableTarget.swift */, + EE235F8F1C5785CE00C08960 /* ConstraintConstantTarget.swift */, + EE235F901C5785CE00C08960 /* ConstraintPriorityTarget.swift */, + EE235F911C5785CE00C08960 /* ConstraintMultiplierTarget.swift */, + EE235F921C5785CE00C08960 /* ConstraintOffsetTarget.swift */, + EE235F931C5785CE00C08960 /* ConstraintInsetTarget.swift */, + ); + name = Targets; + sourceTree = ""; + }; + EE235F5C1C5785A400C08960 /* Models */ = { + isa = PBXGroup; + children = ( + EE235F621C5785C600C08960 /* Constraint.swift */, + EE235F631C5785C600C08960 /* ConstraintDescription.swift */, + 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 */, + ); + name = Models; + sourceTree = ""; + }; + EE235F5D1C5785AC00C08960 /* Debugging */ = { + isa = PBXGroup; + children = ( + EE235F5E1C5785BC00C08960 /* Debugging.swift */, + ); + name = Debugging; + sourceTree = ""; + }; EE94F60C1AC0F113008767FF /* Frameworks */ = { isa = PBXGroup; children = ( @@ -186,19 +317,12 @@ isa = PBXGroup; children = ( EECDB3661AC0C95C006BBC11 /* SnapKit.h */, - EEFCF32E1AD926AE00A425FA /* SnapKit.swift */, - EECDB35E1AC0C95C006BBC11 /* Constraint.swift */, - EEFCF3311AD9432400A425FA /* ConstraintDescription.swift */, - EECDB3611AC0C95C006BBC11 /* ConstraintMaker.swift */, - EECDB3671AC0C95C006BBC11 /* View+SnapKit.swift */, - EE4910971B19A26000A54F1F /* ViewController+SnapKit.swift */, - EECDB3601AC0C95C006BBC11 /* ConstraintItem.swift */, - EECDB3631AC0C95C006BBC11 /* EdgeInsets.swift */, - EECDB3651AC0C95C006BBC11 /* LayoutConstraint.swift */, - EEFCF32B1AD910B900A425FA /* Debugging.swift */, - EECDB3621AC0C95C006BBC11 /* ConstraintRelation.swift */, - EECDB35F1AC0C95C006BBC11 /* ConstraintAttributes.swift */, - 779230431BCB6FC30027CF5F /* SourceLocation.swift */, + EE235F581C57858700C08960 /* Extensions */, + EE235F591C57859200C08960 /* DSLs */, + EE235F5A1C57859900C08960 /* Maker */, + EE235F5B1C57859E00C08960 /* Targets */, + EE235F5C1C5785A400C08960 /* Models */, + EE235F5D1C5785AC00C08960 /* Debugging */, EECDB36B1AC0C967006BBC11 /* Supporting Files */, EECDB3681AC0C95C006BBC11 /* Tests */, ); @@ -462,19 +586,34 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 537DCEA61C35CE2000B5B899 /* LayoutConstraint.swift in Sources */, - 537DCE9F1C35CDB700B5B899 /* ConstraintItem.swift in Sources */, - 537DCEA81C35CE3800B5B899 /* ConstraintRelation.swift in Sources */, - 537DCE9D1C35CDA300B5B899 /* SnapKit.swift in Sources */, - 537DCEA51C35CE1B00B5B899 /* EdgeInsets.swift in Sources */, - 537DCE9C1C35CD9A00B5B899 /* Constraint.swift in Sources */, - 537DCEA41C35CE1500B5B899 /* ViewController+SnapKit.swift in Sources */, - 537DCE9E1C35CDAA00B5B899 /* Debugging.swift in Sources */, - 537DCEA11C35CE0000B5B899 /* ConstraintDescription.swift in Sources */, - 537DCEAA1C35CE4800B5B899 /* SourceLocation.swift in Sources */, - 537DCEA91C35CE3E00B5B899 /* ConstraintAttributes.swift in Sources */, - 537DCEA31C35CE0900B5B899 /* View+SnapKit.swift in Sources */, - 537DCEA21C35CE0500B5B899 /* ConstraintMaker.swift in Sources */, + 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 */, + EE235FB61C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */, + EE235FAD1C5785D400C08960 /* ConstraintMaker.swift in Sources */, + EE235F951C5785CE00C08960 /* ConstraintRelatableTarget.swift in Sources */, + EE235FBC1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */, + EE235F891C5785C600C08960 /* ConstraintItem.swift in Sources */, + EE235F9B1C5785CE00C08960 /* ConstraintPriorityTarget.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 */, + EE235F801C5785C600C08960 /* ConstraintRelation.swift in Sources */, + EE235F711C5785C600C08960 /* ConstraintDescription.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -490,19 +629,34 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - EECDB36C1AC0C9A6006BBC11 /* Constraint.swift in Sources */, - EEFCF32F1AD926AE00A425FA /* SnapKit.swift in Sources */, - EEFCF32C1AD910B900A425FA /* Debugging.swift in Sources */, - EECDB3701AC0C9A6006BBC11 /* ConstraintRelation.swift in Sources */, - EEFCF3321AD9432400A425FA /* ConstraintDescription.swift in Sources */, - EECDB3731AC0C9A6006BBC11 /* View+SnapKit.swift in Sources */, - EECDB3711AC0C9A6006BBC11 /* EdgeInsets.swift in Sources */, - EE4910981B19A26000A54F1F /* ViewController+SnapKit.swift in Sources */, - EECDB36F1AC0C9A6006BBC11 /* ConstraintMaker.swift in Sources */, - 779230441BCB6FC30027CF5F /* SourceLocation.swift in Sources */, - EECDB36D1AC0C9A6006BBC11 /* ConstraintAttributes.swift in Sources */, - EECDB3721AC0C9A6006BBC11 /* LayoutConstraint.swift in Sources */, - EECDB36E1AC0C9A6006BBC11 /* ConstraintItem.swift in Sources */, + 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 */, + EE235FB51C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */, + EE235FAC1C5785D400C08960 /* ConstraintMaker.swift in Sources */, + EE235F941C5785CE00C08960 /* ConstraintRelatableTarget.swift in Sources */, + EE235FBB1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */, + EE235F881C5785C600C08960 /* ConstraintItem.swift in Sources */, + EE235F9A1C5785CE00C08960 /* ConstraintPriorityTarget.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 */, + EE235F7F1C5785C600C08960 /* ConstraintRelation.swift in Sources */, + EE235F701C5785C600C08960 /* ConstraintDescription.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -518,18 +672,34 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - EECDB3951AC0CBFF006BBC11 /* Constraint.swift in Sources */, - EEFCF3301AD92C2200A425FA /* SnapKit.swift in Sources */, - EEFCF32D1AD9250C00A425FA /* Debugging.swift in Sources */, - EECDB3991AC0CBFF006BBC11 /* ConstraintRelation.swift in Sources */, - EEFCF3331AD9432400A425FA /* ConstraintDescription.swift in Sources */, - EECDB39C1AC0CBFF006BBC11 /* View+SnapKit.swift in Sources */, - EECDB39A1AC0CBFF006BBC11 /* EdgeInsets.swift in Sources */, - EECDB3981AC0CBFF006BBC11 /* ConstraintMaker.swift in Sources */, - EECDB3961AC0CBFF006BBC11 /* ConstraintAttributes.swift in Sources */, - 779230451BCB6FC30027CF5F /* SourceLocation.swift in Sources */, - EECDB39B1AC0CBFF006BBC11 /* LayoutConstraint.swift in Sources */, - EECDB3971AC0CBFF006BBC11 /* ConstraintItem.swift in Sources */, + 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 */, + EE235FB71C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */, + EE235FAE1C5785D400C08960 /* ConstraintMaker.swift in Sources */, + EE235F961C5785CE00C08960 /* ConstraintRelatableTarget.swift in Sources */, + EE235FBD1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */, + EE235F8A1C5785C600C08960 /* ConstraintItem.swift in Sources */, + EE235F9C1C5785CE00C08960 /* ConstraintPriorityTarget.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 */, + EE235F811C5785C600C08960 /* ConstraintRelation.swift in Sources */, + EE235F721C5785C600C08960 /* ConstraintDescription.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -555,6 +725,7 @@ 537DCE971C35CC8800B5B899 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; @@ -569,6 +740,7 @@ PRODUCT_NAME = SnapKit; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; @@ -579,6 +751,7 @@ 537DCE981C35CC8800B5B899 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; @@ -716,6 +889,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -728,6 +902,7 @@ PRODUCT_NAME = SnapKit; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -737,6 +912,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -779,6 +955,7 @@ EECDB38E1AC0C9D4006BBC11 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; @@ -799,6 +976,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -807,6 +985,7 @@ EECDB38F1AC0C9D4006BBC11 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; @@ -878,6 +1057,7 @@ 537DCEB81C35D90A00B5B899 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; DDC9FD901981B4DD009612C7 /* Build configuration list for PBXProject "SnapKit" */ = { isa = XCConfigurationList; diff --git a/Source/Constraint.swift b/Source/Constraint.swift index b3fea4b..21d42c7 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -22,241 +22,111 @@ // THE SOFTWARE. #if os(iOS) || os(tvOS) -import UIKit + import UIKit #else -import AppKit + import AppKit #endif -/** - Used to expose API's for a Constraint -*/ + public class Constraint { - public func install() -> [LayoutConstraint] { fatalError("Must be implemented by Concrete subclass.") } - public func uninstall() -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func activate() -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func deactivate() -> Void { fatalError("Must be implemented by Concrete subclass.") } + internal let sourceLocation: (String, UInt) - public func updateOffset(amount: Float) -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updateOffset(amount: Double) -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updateOffset(amount: CGFloat) -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updateOffset(amount: Int) -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updateOffset(amount: UInt) -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updateOffset(amount: CGPoint) -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updateOffset(amount: CGSize) -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updateOffset(amount: EdgeInsets) -> Void { fatalError("Must be implemented by Concrete subclass.") } - - public func updateInsets(amount: EdgeInsets) -> Void { fatalError("Must be implemented by Concrete subclass.") } - - public func updatePriority(priority: Float) -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updatePriority(priority: Double) -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updatePriority(priority: CGFloat) -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updatePriority(priority: UInt) -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updatePriority(priority: Int) -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updatePriorityRequired() -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updatePriorityHigh() -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updatePriorityMedium() -> Void { fatalError("Must be implemented by Concrete subclass.") } - public func updatePriorityLow() -> Void { fatalError("Must be implemented by Concrete subclass.") } - - internal var makerLocation: SourceLocation = SourceLocation(file: "Unknown", line: 0) - - internal(set) public var location: SourceLocation? -} - -/** - Used internally to implement a ConcreteConstraint -*/ -internal class ConcreteConstraint: Constraint { - - internal override func updateOffset(amount: Float) -> Void { - self.constant = amount - } - internal override func updateOffset(amount: Double) -> Void { - self.updateOffset(Float(amount)) - } - internal override func updateOffset(amount: CGFloat) -> Void { - self.updateOffset(Float(amount)) - } - internal override func updateOffset(amount: Int) -> Void { - self.updateOffset(Float(amount)) - } - internal override func updateOffset(amount: UInt) -> Void { - self.updateOffset(Float(amount)) - } - internal override func updateOffset(amount: CGPoint) -> Void { - self.constant = amount - } - internal override func updateOffset(amount: CGSize) -> Void { - self.constant = amount - } - internal override func updateOffset(amount: EdgeInsets) -> Void { - self.constant = amount - } - - internal override func updateInsets(amount: EdgeInsets) -> Void { - self.constant = EdgeInsets(top: amount.top, left: amount.left, bottom: -amount.bottom, right: -amount.right) - } - - internal override func updatePriority(priority: Float) -> Void { - self.priority = priority - } - internal override func updatePriority(priority: Double) -> Void { - self.updatePriority(Float(priority)) - } - internal override func updatePriority(priority: CGFloat) -> Void { - self.updatePriority(Float(priority)) - } - internal override func updatePriority(priority: UInt) -> Void { - self.updatePriority(Float(priority)) - } - internal override func updatePriority(priority: Int) -> Void { - self.updatePriority(Float(priority)) - } - internal override func updatePriorityRequired() -> Void { - self.updatePriority(Float(1000.0)) - } - internal override func updatePriorityHigh() -> Void { - self.updatePriority(Float(750.0)) - } - internal override func updatePriorityMedium() -> Void { - #if os(iOS) || os(tvOS) - self.updatePriority(Float(500.0)) - #else - self.updatePriority(Float(501.0)) - #endif - } - internal override func updatePriorityLow() -> Void { - self.updatePriority(Float(250.0)) - } - - internal override func install() -> [LayoutConstraint] { - return self.installOnView(updateExisting: false, location: self.makerLocation) - } - - internal override func uninstall() -> Void { - self.uninstallFromView() - } - - internal override func activate() -> Void { - guard self.installInfo != nil else { - self.install() - return - } - #if SNAPKIT_DEPLOYMENT_LEGACY - guard #available(iOS 8.0, OSX 10.10, *) else { - self.install() - return - } - #endif - let layoutConstraints = self.installInfo!.layoutConstraints.allObjects as! [LayoutConstraint] - if layoutConstraints.count > 0 { - NSLayoutConstraint.activateConstraints(layoutConstraints) - } - } - - internal override func deactivate() -> Void { - guard self.installInfo != nil else { - return - } - #if SNAPKIT_DEPLOYMENT_LEGACY - guard #available(iOS 8.0, OSX 10.10, *) else { - return - } - #endif - let layoutConstraints = self.installInfo!.layoutConstraints.allObjects as! [LayoutConstraint] - if layoutConstraints.count > 0 { - NSLayoutConstraint.deactivateConstraints(layoutConstraints) - } - } - - private let fromItem: ConstraintItem - private let toItem: ConstraintItem + private let from: ConstraintItem + private let to: ConstraintItem private let relation: ConstraintRelation - private let multiplier: Float - private var constant: Any { - didSet { - if let installInfo = self.installInfo { - for layoutConstraint in installInfo.layoutConstraints.allObjects as! [LayoutConstraint] { - let attribute = (layoutConstraint.secondAttribute == .NotAnAttribute) ? layoutConstraint.firstAttribute : layoutConstraint.secondAttribute - layoutConstraint.constant = attribute.snp_constantForValue(self.constant) - } - } - } - } - private var priority: Float { - didSet { - if let installInfo = self.installInfo { - for layoutConstraint in installInfo.layoutConstraints.allObjects as! [LayoutConstraint] { - layoutConstraint.priority = self.priority - } - } - } - } + private let multiplier: ConstraintMultiplierTarget + private var constant: ConstraintConstantTarget + private var priority: ConstraintPriorityTarget + private var installInfo: ConstraintInstallInfo? = nil - private var installInfo: ConcreteConstraintInstallInfo? = nil + // MARK: Initialization - internal init(fromItem: ConstraintItem, toItem: ConstraintItem, relation: ConstraintRelation, constant: Any, multiplier: Float, priority: Float, location: SourceLocation?) { - self.fromItem = fromItem - self.toItem = toItem + internal init(from: ConstraintItem, + to: ConstraintItem, + relation: ConstraintRelation, + sourceLocation: (String, UInt), + multiplier: ConstraintMultiplierTarget, + constant: ConstraintConstantTarget, + priority: ConstraintPriorityTarget) { + self.from = from + self.to = to self.relation = relation - self.constant = constant + self.sourceLocation = sourceLocation self.multiplier = multiplier + self.constant = constant self.priority = priority - super.init() - self.location = location } - internal func installOnView(updateExisting updateExisting: Bool = false, location: SourceLocation? = nil) -> [LayoutConstraint] { - var installOnView: View? = nil - if self.toItem.view != nil { - installOnView = closestCommonSuperviewFromView(self.fromItem.view, toView: self.toItem.view) - if installOnView == nil { - NSException(name: "Cannot Install Constraint", reason: "No common superview between views (@\(self.makerLocation.file)#\(self.makerLocation.line))", userInfo: nil).raise() - return [] + // MARK: Public + + public func install() -> [NSLayoutConstraint] { + return self.installIfNeeded(updateExisting: false) + } + + public func uninstall() { + self.uninstallIfNeeded() + } + + @available(iOS 8.0, OSX 10.10, *) + public func activate() { + self.activateIfNeeded() + } + + @available(iOS 8.0, OSX 10.10, *) + public func deactivate() { + self.deactivateIfNeeded() + } + + // MARK: Internal + + internal func installIfNeeded(updateExisting updateExisting: Bool = false) -> [NSLayoutConstraint] { + let installOnView: ConstraintView? + + if let view = self.to.view { + guard let closestSuperview = closestCommonSuperviewFromView(self.from.view, toView: view) else { + fatalError("Cannot Install Constraint. No common superview. (\(self.sourceLocation.0), \(self.sourceLocation.1))") } + installOnView = closestSuperview + } else if self.from.attributes.isSubsetOf(ConstraintAttributes.Width + ConstraintAttributes.Height) { + installOnView = self.from.view } else { - - if self.fromItem.attributes.isSubsetOf(ConstraintAttributes.Width.union(.Height)) { - installOnView = self.fromItem.view - } else { - installOnView = self.fromItem.view?.superview - if installOnView == nil { - NSException(name: "Cannot Install Constraint", reason: "Missing superview (@\(self.makerLocation.file)#\(self.self.makerLocation.line))", userInfo: nil).raise() - return [] - } + guard let superview = self.from.view?.superview else { + fatalError("Cannot Install Constraint. No superview. (\(self.sourceLocation.0), \(self.sourceLocation.1))") } + installOnView = superview } - if let installedOnView = self.installInfo?.view { - if installedOnView != installOnView { - NSException(name: "Cannot Install Constraint", reason: "Already installed on different view. (@\(self.makerLocation.file)#\(self.makerLocation.line))", userInfo: nil).raise() - return [] - } - return self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint] ?? [] + guard self.installInfo?.view == nil || + self.installInfo?.view == installOnView else { + fatalError("Cannot Install Constraint. Already installed on different view. (\(self.sourceLocation.0), \(self.sourceLocation.1))") } + // setup array to store new layout constraints var newLayoutConstraints = [LayoutConstraint]() - let layoutFromAttributes = self.fromItem.attributes.layoutAttributes - let layoutToAttributes = self.toItem.attributes.layoutAttributes + + // get attributes + let layoutFromAttributes = self.from.attributes.layoutAttributes + let layoutToAttributes = self.to.attributes.layoutAttributes // get layout from - let layoutFrom: View? = self.fromItem.view + let layoutFrom: ConstraintView = self.from.view! - // get layout relation - let layoutRelation: NSLayoutRelation = self.relation.layoutRelation + // get relation + let layoutRelation = self.relation.layoutRelation for layoutFromAttribute in layoutFromAttributes { // get layout to attribute let layoutToAttribute = (layoutToAttributes.count > 0) ? layoutToAttributes[0] : layoutFromAttribute // get layout constant - let layoutConstant: CGFloat = layoutToAttribute.snp_constantForValue(self.constant) + let layoutConstant: CGFloat = self.constant.layoutConstantForLayoutAttribute(layoutToAttribute) // get layout to #if os(iOS) || os(tvOS) - var layoutTo: AnyObject? = self.toItem.view ?? self.toItem.layoutSupport + var layoutTo: AnyObject? = self.to.view ?? self.to.layoutSupport #else - var layoutTo: AnyObject? = self.toItem.view + var layoutTo: AnyObject? = self.to.view #endif if layoutTo == nil && layoutToAttribute != .Width && layoutToAttribute != .Height { layoutTo = installOnView @@ -264,27 +134,30 @@ internal class ConcreteConstraint: Constraint { // create layout constraint let layoutConstraint = LayoutConstraint( - item: layoutFrom!, + item: layoutFrom, attribute: layoutFromAttribute, relatedBy: layoutRelation, toItem: layoutTo, attribute: layoutToAttribute, - multiplier: CGFloat(self.multiplier), - constant: layoutConstant) + multiplier: self.multiplier.constraintMultiplierTargetValue, + constant: layoutConstant + ) // set priority - layoutConstraint.priority = self.priority + layoutConstraint.priority = self.priority.constraintPriorityTargetValue // set constraint - layoutConstraint.snp_constraint = self + layoutConstraint.constraint = self + // append newLayoutConstraints.append(layoutConstraint) } - // special logic for updating + // updating logic if updateExisting { + // get existing constraints for this view - let existingLayoutConstraints = layoutFrom!.snp_installedLayoutConstraints.reverse() + let existingLayoutConstraints = layoutFrom.snp.installedLayoutConstraints.reverse() // array that will contain only new layout constraints to keep var newLayoutConstraintsToKeep = [LayoutConstraint]() @@ -306,7 +179,7 @@ internal class ConcreteConstraint: Constraint { if updateLayoutConstraint != nil { updateLayoutConstraint!.constant = layoutConstraint.constant } - // otherwise add this layout constraint to new keep list + // otherwise add this layout constraint to new keep list else { newLayoutConstraintsToKeep.append(layoutConstraint) } @@ -317,18 +190,18 @@ internal class ConcreteConstraint: Constraint { } // add constraints - #if SNAPKIT_DEPLOYMENT_LEGACY && !os(OSX) - if #available(iOS 8.0, *) { - NSLayoutConstraint.activateConstraints(newLayoutConstraints) - } else { - installOnView!.addConstraints(newLayoutConstraints) - } + #if SNAPKIT_DEPLOYMENT_LEGACY && (os(iOS) || os(tvOS)) + if #available(iOS 8.0, *) { + NSLayoutConstraint.activateConstraints(newLayoutConstraints) + } else { + installOnView?.addConstraints(newLayoutConstraints) + } #else NSLayoutConstraint.activateConstraints(newLayoutConstraints) #endif // set install info - self.installInfo = ConcreteConstraintInstallInfo(view: installOnView, layoutConstraints: NSHashTable.weakObjectsHashTable()) + self.installInfo = ConstraintInstallInfo(view: installOnView, layoutConstraints: NSHashTable.weakObjectsHashTable()) // store which layout constraints are installed for this constraint for layoutConstraint in newLayoutConstraints { @@ -336,141 +209,86 @@ internal class ConcreteConstraint: Constraint { } // store the layout constraints against the layout from view - layoutFrom!.snp_installedLayoutConstraints += newLayoutConstraints + layoutFrom.snp.appendInstalledLayoutConstraints(newLayoutConstraints) - // return the new constraints return newLayoutConstraints } - internal func uninstallFromView() { - if let installInfo = self.installInfo, - let installedLayoutConstraints = installInfo.layoutConstraints.allObjects as? [LayoutConstraint] { - - if installedLayoutConstraints.count > 0 { - // remove the constraints from the UIView's storage - #if SNAPKIT_DEPLOYMENT_LEGACY && !os(OSX) - if #available(iOS 8.0, *) { - NSLayoutConstraint.deactivateConstraints(installedLayoutConstraints) - } else if let installedOnView = installInfo.view { - installedOnView.removeConstraints(installedLayoutConstraints) - } - #else - NSLayoutConstraint.deactivateConstraints(installedLayoutConstraints) - #endif - - // remove the constraints from the from item view - if let fromView = self.fromItem.view { - fromView.snp_installedLayoutConstraints = fromView.snp_installedLayoutConstraints.filter { - return !installedLayoutConstraints.contains($0) - } - } - } - - } - self.installInfo = nil - } - -} - -private struct ConcreteConstraintInstallInfo { - - weak var view: View? = nil - let layoutConstraints: NSHashTable - -} - -private extension NSLayoutAttribute { - - private func snp_constantForValue(value: Any?) -> CGFloat { - // Float - if let float = value as? Float { - return CGFloat(float) - } - // Double - else if let double = value as? Double { - return CGFloat(double) - } - // UInt - else if let int = value as? Int { - return CGFloat(int) - } - // Int - else if let uint = value as? UInt { - return CGFloat(uint) - } - // CGFloat - else if let float = value as? CGFloat { - return float - } - // CGSize - else if let size = value as? CGSize { - if self == .Width { - return size.width - } else if self == .Height { - return size.height - } - } - // CGPoint - else if let point = value as? CGPoint { - #if os(iOS) || os(tvOS) - switch self { - case .Left, .CenterX, .LeftMargin, .CenterXWithinMargins: return point.x - case .Top, .CenterY, .TopMargin, .CenterYWithinMargins, .Baseline, .FirstBaseline: return point.y - case .Right, .RightMargin: return point.x - case .Bottom, .BottomMargin: return point.y - case .Leading, .LeadingMargin: return point.x - case .Trailing, .TrailingMargin: return point.x - case .Width, .Height, .NotAnAttribute: return CGFloat(0) - } - #else - switch self { - case .Left, .CenterX: return point.x - case .Top, .CenterY, .Baseline: return point.y - case .Right: return point.x - case .Bottom: return point.y - case .Leading: return point.x - case .Trailing: return point.x - case .Width, .Height, .NotAnAttribute: return CGFloat(0) - case .FirstBaseline: return point.y - } - #endif - } - // EdgeInsets - else if let insets = value as? EdgeInsets { - #if os(iOS) || os(tvOS) - switch self { - case .Left, .CenterX, .LeftMargin, .CenterXWithinMargins: return insets.left - case .Top, .CenterY, .TopMargin, .CenterYWithinMargins, .Baseline, .FirstBaseline: return insets.top - case .Right, .RightMargin: return insets.right - case .Bottom, .BottomMargin: return insets.bottom - case .Leading, .LeadingMargin: return (Config.interfaceLayoutDirection == .LeftToRight) ? insets.left : -insets.right - case .Trailing, .TrailingMargin: return (Config.interfaceLayoutDirection == .LeftToRight) ? insets.right : -insets.left - case .Width: return -insets.left + insets.right - case .Height: return -insets.top + insets.bottom - case .NotAnAttribute: return CGFloat(0) - } - #else - switch self { - case .Left, .CenterX: return insets.left - case .Top, .CenterY, .Baseline: return insets.top - case .Right: return insets.right - case .Bottom: return insets.bottom - case .Leading: return (Config.interfaceLayoutDirection == .LeftToRight) ? insets.left : -insets.right - case .Trailing: return (Config.interfaceLayoutDirection == .LeftToRight) ? insets.right : -insets.left - case .Width: return -insets.left + insets.right - case .Height: return -insets.top + insets.bottom - case .NotAnAttribute: return CGFloat(0) - case .FirstBaseline: return insets.bottom - } - #endif + internal func uninstallIfNeeded() { + defer { + self.installInfo = nil } - return CGFloat(0); + guard let installedLayoutConstraints = self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint] + where installedLayoutConstraints.count > 0 else { + return + } + + #if SNAPKIT_DEPLOYMENT_LEGACY && !os(OSX) + if #available(iOS 8.0, *) { + NSLayoutConstraint.deactivateConstraints(installedLayoutConstraints) + } else if let installedOnView = installInfo.view { + installedOnView.removeConstraints(installedLayoutConstraints) + } + #else + NSLayoutConstraint.deactivateConstraints(installedLayoutConstraints) + #endif + + // remove the constraints from the from item view + self.from.view?.snp.removeInstalledLayoutConstraints(installedLayoutConstraints) } + + internal func activateIfNeeded() { + guard self.installInfo != nil else { + self.installIfNeeded() + return + } + #if SNAPKIT_DEPLOYMENT_LEGACY + guard #available(iOS 8.0, OSX 10.10, *) else { + self.installIfNeeded() + return + } + #endif + + guard let layoutConstraints = self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint] + where layoutConstraints.count > 0 else { + return + } + + NSLayoutConstraint.activateConstraints(layoutConstraints) + } + + internal func deactivateIfNeeded() { + #if SNAPKIT_DEPLOYMENT_LEGACY + guard #available(iOS 8.0, OSX 10.10, *) else { + return + } + #endif + + guard let layoutConstraints = self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint] + where layoutConstraints.count > 0 else { + return + } + + NSLayoutConstraint.deactivateConstraints(layoutConstraints) + } + } -private func closestCommonSuperviewFromView(fromView: View?, toView: View?) -> View? { - var views = Set() +private final class ConstraintInstallInfo { + + private weak var view: ConstraintView? = nil + private let layoutConstraints: NSHashTable + + private init(view: ConstraintView?, layoutConstraints: NSHashTable) { + self.view = view + self.layoutConstraints = layoutConstraints + } + +} + +private func closestCommonSuperviewFromView(fromView: ConstraintView?, toView: ConstraintView?) -> ConstraintView? { + var views = Set() var fromView = fromView var toView = toView repeat { @@ -493,10 +311,10 @@ private func closestCommonSuperviewFromView(fromView: View?, toView: View?) -> V return nil } -private func ==(left: ConcreteConstraint, right: ConcreteConstraint) -> Bool { - return (left.fromItem == right.fromItem && - left.toItem == right.toItem && - left.relation == right.relation && - left.multiplier == right.multiplier && - left.priority == right.priority) +private func ==(lhs: Constraint, rhs: Constraint) -> Bool { + return (lhs.from == rhs.from && + lhs.to == rhs.to && + lhs.relation == rhs.relation && + lhs.multiplier == rhs.multiplier && + lhs.priority == rhs.priority) } diff --git a/Source/ConstraintAttributes.swift b/Source/ConstraintAttributes.swift index 95bfddb..6308856 100644 --- a/Source/ConstraintAttributes.swift +++ b/Source/ConstraintAttributes.swift @@ -1,7 +1,7 @@ // // SnapKit // -// Copyright (c) 2011-2015 SnapKit Team - https://github.com/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 @@ -22,14 +22,12 @@ // THE SOFTWARE. #if os(iOS) || os(tvOS) -import UIKit + import UIKit #else -import AppKit + import AppKit #endif -/** - Used to define `NSLayoutAttributes` in a more concise and composite manner -*/ + internal struct ConstraintAttributes: OptionSetType, BooleanType { internal init(rawValue: UInt) { @@ -134,49 +132,56 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType { } #if os(iOS) || os(tvOS) - #if SNAPKIT_DEPLOYMENT_LEGACY - guard #available(iOS 8.0, *) else { - return attrs - } - #endif - if (self.contains(ConstraintAttributes.FirstBaseline)) { - attrs.append(.FirstBaseline) - } - if (self.contains(ConstraintAttributes.LeftMargin)) { - attrs.append(.LeftMargin) - } - if (self.contains(ConstraintAttributes.RightMargin)) { - attrs.append(.RightMargin) - } - if (self.contains(ConstraintAttributes.TopMargin)) { - attrs.append(.TopMargin) - } - if (self.contains(ConstraintAttributes.BottomMargin)) { - attrs.append(.BottomMargin) - } - if (self.contains(ConstraintAttributes.LeadingMargin)) { - attrs.append(.LeadingMargin) - } - if (self.contains(ConstraintAttributes.TrailingMargin)) { - attrs.append(.TrailingMargin) - } - if (self.contains(ConstraintAttributes.CenterXWithinMargins)) { - attrs.append(.CenterXWithinMargins) - } - if (self.contains(ConstraintAttributes.CenterYWithinMargins)) { - attrs.append(.CenterYWithinMargins) - } + #if SNAPKIT_DEPLOYMENT_LEGACY + guard #available(iOS 8.0, *) else { + return attrs + } + #endif + if (self.contains(ConstraintAttributes.FirstBaseline)) { + attrs.append(.FirstBaseline) + } + if (self.contains(ConstraintAttributes.LeftMargin)) { + attrs.append(.LeftMargin) + } + if (self.contains(ConstraintAttributes.RightMargin)) { + attrs.append(.RightMargin) + } + if (self.contains(ConstraintAttributes.TopMargin)) { + attrs.append(.TopMargin) + } + if (self.contains(ConstraintAttributes.BottomMargin)) { + attrs.append(.BottomMargin) + } + if (self.contains(ConstraintAttributes.LeadingMargin)) { + attrs.append(.LeadingMargin) + } + if (self.contains(ConstraintAttributes.TrailingMargin)) { + attrs.append(.TrailingMargin) + } + if (self.contains(ConstraintAttributes.CenterXWithinMargins)) { + attrs.append(.CenterXWithinMargins) + } + if (self.contains(ConstraintAttributes.CenterYWithinMargins)) { + attrs.append(.CenterYWithinMargins) + } #endif return attrs } } + +internal func + (left: ConstraintAttributes, right: ConstraintAttributes) -> ConstraintAttributes { + return left.union(right) +} + internal func +=(inout left: ConstraintAttributes, right: ConstraintAttributes) { left.unionInPlace(right) } + internal func -=(inout left: ConstraintAttributes, right: ConstraintAttributes) { left.subtractInPlace(right) } + internal func ==(left: ConstraintAttributes, right: ConstraintAttributes) -> Bool { return left.rawValue == right.rawValue } diff --git a/Source/SnapKit.swift b/Source/ConstraintConfig.swift similarity index 68% rename from Source/SnapKit.swift rename to Source/ConstraintConfig.swift index 3aa5181..3b58816 100644 --- a/Source/SnapKit.swift +++ b/Source/ConstraintConfig.swift @@ -1,7 +1,7 @@ // // SnapKit // -// Copyright (c) 2011-2015 SnapKit Team - https://github.com/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 @@ -22,21 +22,16 @@ // THE SOFTWARE. #if os(iOS) || os(tvOS) -import UIKit -public typealias InterfaceLayoutDirection = UIUserInterfaceLayoutDirection -public typealias LayoutSupport = UILayoutSupport + import UIKit + public typealias ConstraintInterfaceLayoutDirection = UIUserInterfaceLayoutDirection #else -import AppKit -public typealias InterfaceLayoutDirection = NSUserInterfaceLayoutDirection -public class LayoutSupport {} + import AppKit + public typealias ConstraintInterfaceLayoutDirection = NSUserInterfaceLayoutDirection #endif -/** - Used to configure different parts of SnapKit -*/ -public struct Config { + +public struct ConstraintConfig { - /// The interface layout direction - public static var interfaceLayoutDirection = InterfaceLayoutDirection.LeftToRight + public static var interfaceLayoutDirection: ConstraintInterfaceLayoutDirection = .LeftToRight -} \ No newline at end of file +} diff --git a/Source/ConstraintConstantTarget.swift b/Source/ConstraintConstantTarget.swift new file mode 100644 index 0000000..69dec3f --- /dev/null +++ b/Source/ConstraintConstantTarget.swift @@ -0,0 +1,148 @@ +// +// 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 ConstraintConstantTarget { +} + +extension CGPoint: ConstraintConstantTarget { +} + +extension CGSize: ConstraintConstantTarget { +} + +extension ConstraintInsets: ConstraintConstantTarget { +} + +extension ConstraintConstantTarget { + + internal func layoutConstantForLayoutAttribute(layoutAttribute: NSLayoutAttribute) -> CGFloat { + if let value = self as? Float { + return CGFloat(value) + } + + if let value = self as? Double { + return CGFloat(value) + } + + if let value = self as? Int { + return CGFloat(value) + } + + if let value = self as? UInt { + return CGFloat(value) + } + + if let value = self as? CGFloat { + return value + } + + if let value = self as? CGSize { + if layoutAttribute == .Width { + return value.width + } else if layoutAttribute == .Height { + return value.height + } else { + return 0.0 + } + } + + + if let value = self as? CGPoint { + #if os(iOS) || os(tvOS) + switch layoutAttribute { + case .Left, .Right, .Leading, .Trailing, .CenterX, .LeftMargin, .RightMargin, .LeadingMargin, .TrailingMargin, .CenterXWithinMargins: + return value.x + case .Top, .Bottom, .CenterY, .TopMargin, .BottomMargin, .CenterYWithinMargins, .Baseline, .FirstBaseline: + return value.y + case .Width, .Height, .NotAnAttribute: + return 0.0 + } + #else + switch layoutAttribute { + case .Left, .Right, .Leading, .Trailing, .CenterX: + return value.x + case .Top, .Bottom, .CenterY, .Baseline, .FirstBaseline: + return value.y + case .Width, .Height, .NotAnAttribute: + return 0.0 + } + #endif + } + + if let value = self as? ConstraintInsets { + #if os(iOS) || os(tvOS) + switch layoutAttribute { + case .Left, .LeftMargin, .CenterX, .CenterXWithinMargins: + return value.left + case .Top, .TopMargin, .CenterY, .CenterYWithinMargins, .Baseline, .FirstBaseline: + return value.top + case .Right, .RightMargin: + return value.right + case .Bottom, .BottomMargin: + return value.bottom + case .Leading, .LeadingMargin: + return (ConstraintConfig.interfaceLayoutDirection == .LeftToRight) ? value.left : -value.right + case .Trailing, .TrailingMargin: + return (ConstraintConfig.interfaceLayoutDirection == .LeftToRight) ? value.right : -value.left + case .Width: + return -value.left + value.right + case .Height: + return -value.top + value.bottom + case .NotAnAttribute: + return 0.0 + } + #else + switch layoutAttribute { + case .Left, .CenterX: + return value.left + case .Top, .CenterY, .Baseline, .FirstBaseline: + return value.top + case .Right: + return value.right + case .Bottom: + return value.bottom + case .Leading: + return (ConstraintConfig.interfaceLayoutDirection == .LeftToRight) ? value.left : -value.right + case .Trailing: + return (ConstraintConfig.interfaceLayoutDirection == .LeftToRight) ? value.right : -value.left + case .Width: + return -value.left + value.right + case .Height: + return -value.top + value.bottom + case .NotAnAttribute: + return 0.0 + } + #endif + } + + return 0.0 + } + +} \ No newline at end of file diff --git a/Source/ConstraintDescription.swift b/Source/ConstraintDescription.swift index 153cea7..d0189ae 100644 --- a/Source/ConstraintDescription.swift +++ b/Source/ConstraintDescription.swift @@ -1,7 +1,7 @@ // // SnapKit // -// Copyright (c) 2011-2015 SnapKit Team - https://github.com/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 @@ -22,488 +22,46 @@ // THE SOFTWARE. #if os(iOS) || os(tvOS) -import UIKit + import UIKit #else -import AppKit + import AppKit #endif -public protocol RelationTarget { - var constraintItem: ConstraintItem { get } -} -public protocol FloatConvertible: RelationTarget { - var floatValue: Float { get } -} - -extension FloatConvertible { - public var constraintItem: ConstraintItem { - return ConstraintItem(object: nil, attributes: ConstraintAttributes.None) - } -} - -extension Float: FloatConvertible, RelationTarget { - public var floatValue: Float { - return self - } -} - -extension Int: FloatConvertible, RelationTarget { - public var floatValue: Float { - return Float(self) - } -} - -extension UInt: FloatConvertible, RelationTarget { - public var floatValue: Float { - return Float(self) - } -} - -extension Double: FloatConvertible, RelationTarget { - public var floatValue: Float { - return Float(self) - } -} - -extension CGFloat: FloatConvertible, RelationTarget { - public var floatValue: Float { - return Float(self) - } -} - -@available(iOS 9.0, OSX 10.11, *) -extension NSLayoutAnchor: RelationTarget { - public var constraintItem: ConstraintItem { - return ConstraintItem(object: self, attributes: ConstraintAttributes.None) - } -} - -extension CGPoint: RelationTarget { - public var constraintItem: ConstraintItem { - return ConstraintItem(object: nil, attributes: ConstraintAttributes.None) - } -} - -extension CGSize: RelationTarget { - public var constraintItem: ConstraintItem { - return ConstraintItem(object: nil, attributes: ConstraintAttributes.None) - } -} - -extension EdgeInsets: RelationTarget { - public var constraintItem: ConstraintItem { - return ConstraintItem(object: nil, attributes: ConstraintAttributes.None) - } -} - -extension View: RelationTarget { - public var constraintItem: ConstraintItem { - return ConstraintItem(object: self, attributes: ConstraintAttributes.None) - } -} - -extension ConstraintItem: RelationTarget { - public var constraintItem: ConstraintItem { - return self - } -} - -/** - Used to expose the final API of a `ConstraintDescription` which allows getting a constraint from it - */ -public class ConstraintDescriptionFinalizable { +public class ConstraintDescription { - private let backing: ConstraintDescription - - internal init(_ backing: ConstraintDescription) { - self.backing = backing - } - - public var constraint: Constraint { - return backing.constraint - } -} - -/** - Used to expose priority APIs - */ -public class ConstraintDescriptionPriortizable: ConstraintDescriptionFinalizable { - - public func priority(priority: FloatConvertible) -> ConstraintDescriptionFinalizable { - return ConstraintDescriptionFinalizable(self.backing.priority(priority)) - } - - public func priorityRequired() -> ConstraintDescriptionFinalizable { - return ConstraintDescriptionFinalizable(self.backing.priorityRequired()) - } - public func priorityHigh() -> ConstraintDescriptionFinalizable { - return ConstraintDescriptionFinalizable(self.backing.priorityHigh()) - } - public func priorityMedium() -> ConstraintDescriptionFinalizable { - return ConstraintDescriptionFinalizable(self.backing.priorityMedium()) - } - public func priorityLow() -> ConstraintDescriptionFinalizable { - return ConstraintDescriptionFinalizable(self.backing.priorityLow()) - } -} - -/** - Used to expose multiplier & constant APIs -*/ -public class ConstraintDescriptionEditable: ConstraintDescriptionPriortizable { - - public func multipliedBy(amount: FloatConvertible) -> ConstraintDescriptionEditable { - return ConstraintDescriptionEditable(self.backing.multipliedBy(amount)) - } - - public func dividedBy(amount: FloatConvertible) -> ConstraintDescriptionEditable { - return self.multipliedBy(1 / amount.floatValue) - } - - public func offset(amount: FloatConvertible) -> ConstraintDescriptionEditable { - return ConstraintDescriptionEditable(self.backing.offset(amount)) - } - public func offset(amount: CGPoint) -> ConstraintDescriptionEditable { - return ConstraintDescriptionEditable(self.backing.offset(amount)) - } - public func offset(amount: CGSize) -> ConstraintDescriptionEditable { - return ConstraintDescriptionEditable(self.backing.offset(amount)) - } - public func offset(amount: EdgeInsets) -> ConstraintDescriptionEditable { - return ConstraintDescriptionEditable(self.backing.offset(amount)) - } - - public func inset(amount: FloatConvertible) -> ConstraintDescriptionEditable { - return ConstraintDescriptionEditable(self.backing.inset(amount)) - } - public func inset(amount: EdgeInsets) -> ConstraintDescriptionEditable { - return ConstraintDescriptionEditable(self.backing.inset(amount)) - } -} - -/** - Used to expose relation APIs -*/ -public class ConstraintDescriptionRelatable { - - private let backing: ConstraintDescription - - init(_ backing: ConstraintDescription) { - self.backing = backing - } - - public func equalTo(other: RelationTarget, file: String = __FILE__, line: UInt = __LINE__) -> ConstraintDescriptionEditable { - let location = SourceLocation(file: file, line: line) - return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .Equal, location: location)) - } - public func equalTo(other: LayoutSupport, file: String = __FILE__, line: UInt = __LINE__) -> ConstraintDescriptionEditable { - let location = SourceLocation(file: file, line: line) - return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .Equal, location: location)) - } - - public func lessThanOrEqualTo(other: RelationTarget, file: String = __FILE__, line: UInt = __LINE__) -> ConstraintDescriptionEditable { - let location = SourceLocation(file: file, line: line) - return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .LessThanOrEqualTo, location: location)) - } - public func lessThanOrEqualTo(other: LayoutSupport, file: String = __FILE__, line: UInt = __LINE__) -> ConstraintDescriptionEditable { - let location = SourceLocation(file: file, line: line) - return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .LessThanOrEqualTo, location: location)) - } - - public func greaterThanOrEqualTo(other: RelationTarget, file: String = __FILE__, line: UInt = __LINE__) -> ConstraintDescriptionEditable { - let location = SourceLocation(file: file, line: line) - return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .GreaterThanOrEqualTo, location: location)) - } - public func greaterThanOrEqualTo(other: LayoutSupport, file: String = __FILE__, line: UInt = __LINE__) -> ConstraintDescriptionEditable { - let location = SourceLocation(file: file, line: line) - return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .GreaterThanOrEqualTo, location: location)) - } -} - -/** - Used to expose chaining APIs -*/ -public class ConstraintDescriptionExtendable: ConstraintDescriptionRelatable { - - public var left: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.left) - } - public var top: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.top) - } - public var bottom: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.bottom) - } - public var right: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.right) - } - public var leading: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.leading) - } - public var trailing: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.trailing) - } - public var width: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.width) - } - public var height: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.height) - } - public var centerX: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.centerX) - } - public var centerY: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.centerY) - } - public var baseline: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.baseline) - } - - @available(iOS 8.0, *) - public var firstBaseline: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.firstBaseline) - } - @available(iOS 8.0, *) - public var leftMargin: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.leftMargin) - } - @available(iOS 8.0, *) - public var rightMargin: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.rightMargin) - } - @available(iOS 8.0, *) - public var topMargin: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.topMargin) - } - @available(iOS 8.0, *) - public var bottomMargin: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.bottomMargin) - } - @available(iOS 8.0, *) - public var leadingMargin: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.leadingMargin) - } - @available(iOS 8.0, *) - public var trailingMargin: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.trailingMargin) - } - @available(iOS 8.0, *) - public var centerXWithinMargins: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.centerXWithinMargins) - } - @available(iOS 8.0, *) - public var centerYWithinMargins: ConstraintDescriptionExtendable { - return ConstraintDescriptionExtendable(self.backing.centerYWithinMargins) - } -} - -/** - Used to internally manage building constraint - */ -internal class ConstraintDescription { - - private var location: SourceLocation? = nil - - private var left: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Left) } - private var top: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Top) } - private var right: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Right) } - private var bottom: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Bottom) } - private var leading: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Leading) } - private var trailing: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Trailing) } - private var width: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Width) } - private var height: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Height) } - private var centerX: ConstraintDescription { return self.addConstraint(ConstraintAttributes.CenterX) } - private var centerY: ConstraintDescription { return self.addConstraint(ConstraintAttributes.CenterY) } - private var baseline: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Baseline) } - - @available(iOS 8.0, *) - private var firstBaseline: ConstraintDescription { return self.addConstraint(ConstraintAttributes.FirstBaseline) } - @available(iOS 8.0, *) - private var leftMargin: ConstraintDescription { return self.addConstraint(ConstraintAttributes.LeftMargin) } - @available(iOS 8.0, *) - private var rightMargin: ConstraintDescription { return self.addConstraint(ConstraintAttributes.RightMargin) } - @available(iOS 8.0, *) - private var topMargin: ConstraintDescription { return self.addConstraint(ConstraintAttributes.TopMargin) } - @available(iOS 8.0, *) - private var bottomMargin: ConstraintDescription { return self.addConstraint(ConstraintAttributes.BottomMargin) } - @available(iOS 8.0, *) - private var leadingMargin: ConstraintDescription { return self.addConstraint(ConstraintAttributes.LeadingMargin) } - @available(iOS 8.0, *) - private var trailingMargin: ConstraintDescription { return self.addConstraint(ConstraintAttributes.TrailingMargin) } - @available(iOS 8.0, *) - private var centerXWithinMargins: ConstraintDescription { return self.addConstraint(ConstraintAttributes.CenterXWithinMargins) } - @available(iOS 8.0, *) - private var centerYWithinMargins: ConstraintDescription { return self.addConstraint(ConstraintAttributes.CenterYWithinMargins) } - - // MARK: initializer - - init(fromItem: ConstraintItem) { - self.fromItem = fromItem - self.toItem = ConstraintItem(object: nil, attributes: ConstraintAttributes.None) - } - - // MARK: multiplier - - private func multipliedBy(amount: FloatConvertible) -> ConstraintDescription { - self.multiplier = amount.floatValue - return self - } - - private func dividedBy(amount: FloatConvertible) -> ConstraintDescription { - self.multiplier = 1.0 / amount.floatValue; - return self - } - - // MARK: offset - - private func offset(amount: FloatConvertible) -> ConstraintDescription { - self.constant = amount.floatValue - return self - } - private func offset(amount: CGPoint) -> ConstraintDescription { - self.constant = amount - return self - } - private func offset(amount: CGSize) -> ConstraintDescription { - self.constant = amount - return self - } - private func offset(amount: EdgeInsets) -> ConstraintDescription { - self.constant = amount - return self - } - - // MARK: inset - - private func inset(amount: FloatConvertible) -> ConstraintDescription { - let value = CGFloat(amount.floatValue) - self.constant = EdgeInsets(top: value, left: value, bottom: -value, right: -value) - return self - } - private func inset(amount: EdgeInsets) -> ConstraintDescription { - self.constant = EdgeInsets(top: amount.top, left: amount.left, bottom: -amount.bottom, right: -amount.right) - return self - } - - // MARK: priority - - private func priority(priority: FloatConvertible) -> ConstraintDescription { - self.priority = priority.floatValue - return self - } - private func priorityRequired() -> ConstraintDescription { - return self.priority(1000.0) - } - private func priorityHigh() -> ConstraintDescription { - return self.priority(750.0) - } - private func priorityMedium() -> ConstraintDescription { - #if os(iOS) || os(tvOS) - return self.priority(500.0) - #else - return self.priority(501.0) - #endif - } - private func priorityLow() -> ConstraintDescription { - return self.priority(250.0) - } - - // MARK: Constraint - - internal var constraint: Constraint { - if self.concreteConstraint == nil { - if self.relation == nil { - fatalError("Attempting to create a constraint from a ConstraintDescription before it has been fully chained.") - } - self.concreteConstraint = ConcreteConstraint( - fromItem: self.fromItem, - toItem: self.toItem, - relation: self.relation!, - constant: self.constant, - multiplier: self.multiplier, - priority: self.priority, - location: self.location - ) + internal let view: ConstraintView + internal var attributes: ConstraintAttributes + internal var relation: ConstraintRelation? = nil + internal var sourceLocation: (String, UInt)? = nil + internal var related: ConstraintItem? = nil + internal var multiplier: ConstraintMultiplierTarget = 1.0 + internal var constant: ConstraintConstantTarget = 0.0 + internal var priority: ConstraintPriorityTarget = 1000.0 + internal var constraint: Constraint? { + guard let relation = self.relation, + let related = self.related, + let sourceLocation = self.sourceLocation else { + return nil } - return self.concreteConstraint! - } - - // MARK: Private - - private let fromItem: ConstraintItem - private var toItem: ConstraintItem { - willSet { - if self.concreteConstraint != nil { - fatalError("Attempting to modify a ConstraintDescription after its constraint has been created.") - } - } - } - private var relation: ConstraintRelation? { - willSet { - if self.concreteConstraint != nil { - fatalError("Attempting to modify a ConstraintDescription after its constraint has been created.") - } - } - } - private var constant: Any = Float(0.0) { - willSet { - if self.concreteConstraint != nil { - fatalError("Attempting to modify a ConstraintDescription after its constraint has been created.") - } - } - } - private var multiplier: Float = 1.0 { - willSet { - if self.concreteConstraint != nil { - fatalError("Attempting to modify a ConstraintDescription after its constraint has been created.") - } - } - } - private var priority: Float = 1000.0 { - willSet { - if self.concreteConstraint != nil { - fatalError("Attempting to modify a ConstraintDescription after its constraint has been created.") - } - } - } - private var concreteConstraint: ConcreteConstraint? = nil - - private func addConstraint(attributes: ConstraintAttributes) -> ConstraintDescription { - if self.relation == nil { - self.fromItem.attributes += attributes - } - return self - } - - private func constrainTo(other: RelationTarget, relation: ConstraintRelation, location: SourceLocation) -> ConstraintDescription { + let from = ConstraintItem(target: self.view, attributes: self.attributes) - self.location = location - - if let constant = other as? FloatConvertible { - self.constant = constant.floatValue - } - - let item = other.constraintItem - - if item.attributes != ConstraintAttributes.None { - let toLayoutAttributes = item.attributes.layoutAttributes - if toLayoutAttributes.count > 1 { - let fromLayoutAttributes = self.fromItem.attributes.layoutAttributes - if toLayoutAttributes != fromLayoutAttributes { - NSException(name: "Invalid Constraint", reason: "Cannot constrain to multiple non identical attributes", userInfo: nil).raise() - return self - } - item.attributes = ConstraintAttributes.None - } - } - self.toItem = item - self.relation = relation - return self + return Constraint( + from: from, + to: related, + relation: relation, + sourceLocation: sourceLocation, + multiplier: self.multiplier, + constant: self.constant, + priority: self.priority + ) } - @available(iOS 7.0, *) - private func constrainTo(other: LayoutSupport, relation: ConstraintRelation, location: SourceLocation) -> ConstraintDescription { - return constrainTo(ConstraintItem(object: other, attributes: ConstraintAttributes.None), relation: relation, location: location) + // MARK: Initialization + + internal init(view: ConstraintView, attributes: ConstraintAttributes) { + self.view = view + self.attributes = attributes } } diff --git a/Source/EdgeInsets.swift b/Source/ConstraintInsetTarget.swift similarity index 62% rename from Source/EdgeInsets.swift rename to Source/ConstraintInsetTarget.swift index 299874a..df528e2 100644 --- a/Source/EdgeInsets.swift +++ b/Source/ConstraintInsetTarget.swift @@ -1,7 +1,7 @@ // // SnapKit // -// Copyright (c) 2011-2015 SnapKit Team - https://github.com/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 @@ -22,17 +22,29 @@ // THE SOFTWARE. #if os(iOS) || os(tvOS) -import UIKit -public typealias EdgeInsets = UIEdgeInsets -public func EdgeInsetsMake(top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> EdgeInsets { - return EdgeInsets(top: top, left: left, bottom: bottom, right: right) -} -public let EdgeInsetsZero = EdgeInsets(top: 0, left: 0, bottom: 0, right: 0) + import UIKit #else -import AppKit -public typealias EdgeInsets = NSEdgeInsets -public func EdgeInsetsMake(top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> EdgeInsets { - return EdgeInsets(top: top, left: left, bottom: bottom, right: right) -} -public let EdgeInsetsZero = EdgeInsets(top: 0, left: 0, bottom: 0, right: 0) + import AppKit #endif + + +public protocol ConstraintInsetTarget: ConstraintConstantTarget { +} + +extension Int: ConstraintInsetTarget { +} + +extension UInt: ConstraintInsetTarget { +} + +extension Float: ConstraintInsetTarget { +} + +extension Double: ConstraintInsetTarget { +} + +extension CGFloat: ConstraintInsetTarget { +} + +extension ConstraintInsets: ConstraintInsetTarget { +} diff --git a/Source/ConstraintInsets.swift b/Source/ConstraintInsets.swift new file mode 100644 index 0000000..738ca05 --- /dev/null +++ b/Source/ConstraintInsets.swift @@ -0,0 +1,35 @@ +// +// 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 + + +#if os(iOS) || os(tvOS) + public typealias ConstraintInsets = UIEdgeInsets +#else + public typealias ConstraintInsets = NSEdgeInsets +#endif diff --git a/Source/ConstraintItem.swift b/Source/ConstraintItem.swift index b2c9062..6ff291e 100644 --- a/Source/ConstraintItem.swift +++ b/Source/ConstraintItem.swift @@ -1,7 +1,7 @@ // // SnapKit // -// Copyright (c) 2011-2015 SnapKit Team - https://github.com/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 @@ -22,47 +22,44 @@ // THE SOFTWARE. #if os(iOS) || os(tvOS) -import UIKit + import UIKit #else -import AppKit + import AppKit #endif -/** - Used to assist in building a constraint -*/ -public class ConstraintItem { + +public class ConstraintItem: Equatable { - internal init(object: AnyObject?, attributes: ConstraintAttributes) { - self.object = object + internal weak var target: AnyObject? + internal let attributes: ConstraintAttributes + + internal init(target: AnyObject?, attributes: ConstraintAttributes) { + self.target = target self.attributes = attributes } - internal weak var object: AnyObject? - internal var attributes: ConstraintAttributes - - internal var view: View? { - return self.object as? View + internal var view: ConstraintView? { + return self.target as? ConstraintView } - @available(iOS 7.0, *) - internal var layoutSupport: LayoutSupport? { - return self.object as? LayoutSupport + internal var layoutSupport: ConstraintLayoutSupport? { + return self.target as? ConstraintLayoutSupport } + } - -internal func ==(left: ConstraintItem, right: ConstraintItem) -> Bool { - if left.object == nil { - return false +public func ==(lhs: ConstraintItem, rhs: ConstraintItem) -> Bool { + // pointer equality + guard lhs !== rhs else { + return true } - if right.object == nil { - return false - } - if left.object !== right.object { - return false - } - if left.attributes != right.attributes { - return false + + // must both have valid targets and identical attributes + guard let target1 = lhs.target, + let target2 = rhs.target + where target1 === target2 && lhs.attributes == rhs.attributes else { + return false } + return true -} \ No newline at end of file +} diff --git a/Source/SourceLocation.swift b/Source/ConstraintLayoutSupport.swift similarity index 85% rename from Source/SourceLocation.swift rename to Source/ConstraintLayoutSupport.swift index b148e49..60f4aff 100644 --- a/Source/SourceLocation.swift +++ b/Source/ConstraintLayoutSupport.swift @@ -21,16 +21,10 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -public struct SourceLocation { - - public let file: String - public let line: UInt - - init(file: String, line: UInt) { - self.file = file - self.line = line - } - -} - - +#if os(iOS) || os(tvOS) + import UIKit + internal typealias ConstraintLayoutSupport = UILayoutSupport +#else + import AppKit + internal class ConstraintLayoutSupport { } +#endif \ No newline at end of file diff --git a/Source/ConstraintMaker.swift b/Source/ConstraintMaker.swift index ec20db1..3ece978 100644 --- a/Source/ConstraintMaker.swift +++ b/Source/ConstraintMaker.swift @@ -1,7 +1,7 @@ // // SnapKit // -// Copyright (c) 2011-2015 SnapKit Team - https://github.com/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 @@ -22,169 +22,160 @@ // THE SOFTWARE. #if os(iOS) || os(tvOS) -import UIKit + import UIKit #else -import AppKit + import AppKit #endif -/** - Used to make constraints -*/ public class ConstraintMaker { - /// left edge - public var left: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Left) } + public var left: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.Left) + } + public var top: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.Top) + } + public var bottom: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.Bottom) + } + public var right: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.Right) + } + public var leading: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.Leading) + } + public var trailing: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.Trailing) + } + public var width: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.Width) + } + public var height: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.Height) + } - /// top edge - public var top: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Top) } + public var centerX: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.CenterX) + } + public var centerY: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.CenterY) + } + public var baseline: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.Baseline) + } - /// right edge - public var right: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Right) } - - /// bottom edge - public var bottom: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Bottom) } - - /// leading edge - public var leading: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Leading) } - - /// trailing edge - public var trailing: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Trailing) } - - /// width dimension - public var width: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Width) } - - /// height dimension - public var height: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Height) } - - /// centerX dimension - public var centerX: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterX) } - - /// centerY dimension - public var centerY: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterY) } - - /// baseline position - public var baseline: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Baseline) } - - /// firse baseline position @available(iOS 8.0, *) - public var firstBaseline: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.FirstBaseline) } + public var firstBaseline: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.FirstBaseline) + } - /// left margin @available(iOS 8.0, *) - public var leftMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.LeftMargin) } + public var leftMargin: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.LeftMargin) + } - /// right margin @available(iOS 8.0, *) - public var rightMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.RightMargin) } + public var rightMargin: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.RightMargin) + } - /// top margin @available(iOS 8.0, *) - public var topMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.TopMargin) } + public var bottomMargin: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.BottomMargin) + } - /// bottom margin @available(iOS 8.0, *) - public var bottomMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.BottomMargin) } + public var leadingMargin: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.LeadingMargin) + } - /// leading margin @available(iOS 8.0, *) - public var leadingMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.LeadingMargin) } + public var trailingMargin: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.TrailingMargin) + } - /// trailing margin @available(iOS 8.0, *) - public var trailingMargin: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.TrailingMargin) } + public var centerXWithinMargins: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.CenterXWithinMargins) + } - /// centerX within margins @available(iOS 8.0, *) - public var centerXWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterXWithinMargins) } + public var centerYWithinMargins: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.CenterYWithinMargins) + } + + public var edges: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.Edges) + } + public var size: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.Size) + } - /// centerY within margins @available(iOS 8.0, *) - public var centerYWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterYWithinMargins) } + public var margins: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.Margins) + } - /// top + left + bottom + right edges - public var edges: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Edges) } - - /// width + height dimensions - public var size: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Size) } - - // centerX + centerY positions - public var center: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Center) } - - // top + left + bottom + right margins @available(iOS 8.0, *) - public var margins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.Margins) } + public var centerWithinMargins: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(ConstraintAttributes.CenterWithinMargins) + } - // centerX + centerY within margins - @available(iOS 8.0, *) - public var centerWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterWithinMargins) } + private let view: ConstraintView + private var descriptions = [ConstraintDescription]() - internal init(view: View, location: SourceLocation) { + internal init(view: ConstraintView) { self.view = view - self.location = location + self.view.translatesAutoresizingMaskIntoConstraints = false } - internal let location: SourceLocation - internal let view: View - internal var constraintDescriptions = [ConstraintDescription]() - - internal func makeConstraintDescription(attributes: ConstraintAttributes) -> ConstraintDescriptionExtendable { - let item = ConstraintItem(object: self.view, attributes: attributes) - let constraintDescription = ConstraintDescription(fromItem: item) - self.constraintDescriptions.append(constraintDescription) - return ConstraintDescriptionExtendable(constraintDescription) + internal func makeExtendableWithAttributes(attributes: ConstraintAttributes) -> ConstraintMakerExtendable { + let description = ConstraintDescription(view: self.view, attributes: attributes) + self.descriptions.append(description) + return ConstraintMakerExtendable(description) } - internal class func prepareConstraints(view view: View, location: SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] { - let maker = ConstraintMaker(view: view, location: location) + internal static func prepareConstraints(view view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] { + let maker = ConstraintMaker(view: view) closure(make: maker) - - let constraints = maker.constraintDescriptions.map { $0.constraint } - for constraint in constraints { - constraint.makerLocation = maker.location - } + let constraints = maker.descriptions + .map { $0.constraint } + .filter { $0 != nil } + .map { $0! } return constraints } - internal class func makeConstraints(view view: View, location: SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) { - view.translatesAutoresizingMaskIntoConstraints = false - let maker = ConstraintMaker(view: view, location: location) + internal static func makeConstraints(view view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { + let maker = ConstraintMaker(view: view) closure(make: maker) - - let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint } + let constraints = maker.descriptions + .map { $0.constraint } + .filter { $0 != nil } + .map { $0! } for constraint in constraints { - constraint.makerLocation = maker.location - constraint.installOnView(updateExisting: false) + constraint.installIfNeeded() } } - internal class func remakeConstraints(view view: View, location: SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) { - view.translatesAutoresizingMaskIntoConstraints = false - let maker = ConstraintMaker(view: view, location: location) - closure(make: maker) - + internal static func remakeConstraints(view view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { self.removeConstraints(view: view) - let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint } - for constraint in constraints { - constraint.makerLocation = maker.location - constraint.installOnView(updateExisting: false) - } + self.makeConstraints(view: view, closure: closure) } - internal class func updateConstraints(view view: View, location: SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) { - view.translatesAutoresizingMaskIntoConstraints = false - let maker = ConstraintMaker(view: view, location: location) + internal static func updateConstraints(view view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { + let maker = ConstraintMaker(view: view) closure(make: maker) - - let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint} + let constraints = maker.descriptions + .map { $0.constraint } + .filter { $0 != nil } + .map { $0! } for constraint in constraints { - constraint.makerLocation = maker.location - constraint.installOnView(updateExisting: true) + constraint.installIfNeeded(updateExisting: true) } } - internal class func removeConstraints(view view: View) { - for existingLayoutConstraint in view.snp_installedLayoutConstraints { - existingLayoutConstraint.snp_constraint?.uninstall() - } + internal static func removeConstraints(view view: ConstraintView) { + } + } diff --git a/Source/ConstraintMakerEditable.swift b/Source/ConstraintMakerEditable.swift new file mode 100644 index 0000000..2f6c37b --- /dev/null +++ b/Source/ConstraintMakerEditable.swift @@ -0,0 +1,71 @@ +// +// 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 class ConstraintMakerEditable: ConstraintMakerPriortizable { + + public func multipliedBy(amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable { + self.description.multiplier = amount + return self + } + + public func dividedBy(amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable { + return self.multipliedBy(1.0 / amount.constraintMultiplierTargetValue) + } + + public func offset(amount: ConstraintOffsetTarget) -> ConstraintMakerEditable { + self.description.constant = amount + return self + } + + public func inset(amount: ConstraintInsetTarget) -> ConstraintMakerEditable { + let insets: ConstraintInsets + + if let amount = amount as? ConstraintInsets { + insets = amount + } else if let amount = amount as? Float { + insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) + } else if let amount = amount as? Double { + insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) + } else if let amount = amount as? CGFloat { + insets = ConstraintInsets(top: amount, left: amount, bottom: amount, right: amount) + } else if let amount = amount as? Int { + insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) + } else if let amount = amount as? UInt { + insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) + } else { + insets = ConstraintInsets(top: 0, left: 0, bottom: 0, right: 0) + } + + self.description.constant = ConstraintInsets(top: insets.top, left: insets.left, bottom: -insets.bottom, right: -insets.right) + + return self + } + +} diff --git a/Source/ConstraintMakerExtendable.swift b/Source/ConstraintMakerExtendable.swift new file mode 100644 index 0000000..220bf16 --- /dev/null +++ b/Source/ConstraintMakerExtendable.swift @@ -0,0 +1,157 @@ +// +// 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 class ConstraintMakerExtendable: ConstraintMakerRelatable { + + public var left: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.Left + return self + } + + public var top: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.Top + return self + } + + public var bottom: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.Bottom + return self + } + + public var right: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.Right + return self + } + + public var leading: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.Leading + return self + } + + public var trailing: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.Trailing + return self + } + + public var width: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.Width + return self + } + + public var height: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.Height + return self + } + + public var centerX: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.CenterX + return self + } + + public var centerY: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.CenterY + return self + } + + public var baseline: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.Baseline + return self + } + + @available(iOS 8.0, *) + public var firstBaseline: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.FirstBaseline + return self + } + + @available(iOS 8.0, *) + public var leftMargin: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.LeftMargin + return self + } + + @available(iOS 8.0, *) + public var rightMargin: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.RightMargin + return self + } + + @available(iOS 8.0, *) + public var bottomMargin: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.BottomMargin + return self + } + + @available(iOS 8.0, *) + public var leadingMargin: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.LeadingMargin + return self + } + + @available(iOS 8.0, *) + public var trailingMargin: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.TrailingMargin + return self + } + + @available(iOS 8.0, *) + public var centerXWithinMargins: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.CenterXWithinMargins + return self + } + + @available(iOS 8.0, *) + public var centerYWithinMargins: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.CenterYWithinMargins + return self + } + + public var edges: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.Edges + return self + } + public var size: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.Size + return self + } + + @available(iOS 8.0, *) + public var margins: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.Margins + return self + } + + @available(iOS 8.0, *) + public var centerWithinMargins: ConstraintMakerExtendable { + self.description.attributes += ConstraintAttributes.CenterWithinMargins + return self + } + +} diff --git a/Source/ConstraintMakerFinalizable.swift b/Source/ConstraintMakerFinalizable.swift new file mode 100644 index 0000000..480f9c8 --- /dev/null +++ b/Source/ConstraintMakerFinalizable.swift @@ -0,0 +1,43 @@ +// +// 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 class ConstraintMakerFinalizable { + + internal let description: ConstraintDescription + + internal init(_ description: ConstraintDescription) { + self.description = description + } + + public var constraint: Constraint { + return self.description.constraint! + } + +} diff --git a/Source/ViewController+SnapKit.swift b/Source/ConstraintMakerPriortizable.swift similarity index 56% rename from Source/ViewController+SnapKit.swift rename to Source/ConstraintMakerPriortizable.swift index ed5451b..81bec09 100644 --- a/Source/ViewController+SnapKit.swift +++ b/Source/ConstraintMakerPriortizable.swift @@ -1,7 +1,7 @@ // // SnapKit // -// Copyright (c) 2011-2015 SnapKit Team - https://github.com/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 @@ -22,24 +22,37 @@ // THE SOFTWARE. #if os(iOS) || os(tvOS) -import UIKit + import UIKit +#else + import AppKit +#endif -/** - Used to expose public API on view controllers -*/ -public extension UIViewController { + +public class ConstraintMakerPriortizable: ConstraintMakerFinalizable { - /// top layout guide top - public var snp_topLayoutGuideTop: ConstraintItem { return ConstraintItem(object: self.topLayoutGuide, attributes: ConstraintAttributes.Top) } + public func priority(amount: ConstraintPriorityTarget) -> ConstraintMakerFinalizable { + self.description.priority = amount + return self + } - /// top layout guide bottom - public var snp_topLayoutGuideBottom: ConstraintItem { return ConstraintItem(object: self.topLayoutGuide, attributes: ConstraintAttributes.Bottom) } + public func priorityRequired() -> ConstraintMakerFinalizable { + return self.priority(1000) + } - /// bottom layout guide top - public var snp_bottomLayoutGuideTop: ConstraintItem { return ConstraintItem(object: self.bottomLayoutGuide, attributes: ConstraintAttributes.Top) } + public func priorityHigh() -> ConstraintMakerFinalizable { + return self.priority(750) + } - /// bottom layout guide bottom - public var snp_bottomLayoutGuideBottom: ConstraintItem { return ConstraintItem(object: self.bottomLayoutGuide, attributes: ConstraintAttributes.Bottom) } + public func priorityMedium() -> ConstraintMakerFinalizable { + #if os(iOS) || os(tvOS) + return self.priority(500) + #else + return self.priority(501) + #endif + } + + public func priorityLow() -> ConstraintMakerFinalizable { + return self.priority(250) + } } -#endif diff --git a/Source/ConstraintMakerRelatable.swift b/Source/ConstraintMakerRelatable.swift new file mode 100644 index 0000000..e5d92cc --- /dev/null +++ b/Source/ConstraintMakerRelatable.swift @@ -0,0 +1,82 @@ +// +// 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 class ConstraintMakerRelatable { + + internal let description: ConstraintDescription + + internal init(_ description: ConstraintDescription) { + self.description = description + } + + internal func relatedTo(other: ConstraintRelatableTarget, relation: ConstraintRelation, file: String, line: UInt) -> ConstraintMakerEditable { + let related: ConstraintItem + let constant: ConstraintConstantTarget + + if let other = other as? ConstraintItem { + guard other.attributes == ConstraintAttributes.None || + other.attributes.layoutAttributes.count <= 1 || + other.attributes.layoutAttributes == self.description.attributes.layoutAttributes else { + fatalError("Cannot constraint to multiple non identical attributes. (\(file), \(line))"); + } + + related = other + constant = 0.0 + } else if let other = other as? ConstraintView { + related = ConstraintItem(target: other, attributes: ConstraintAttributes.None) + constant = 0.0 + } else if let other = other as? ConstraintConstantTarget { + related = ConstraintItem(target: nil, attributes: ConstraintAttributes.None) + constant = other + } else { + fatalError("Invalid constraint. (\(file), \(line))") + } + + let editable = ConstraintMakerEditable(self.description) + editable.description.sourceLocation = (file, line) + editable.description.relation = relation + editable.description.related = related + editable.description.constant = constant + return editable + } + + public func equalTo(other: ConstraintRelatableTarget, _ file: String = __FILE__, _ line: UInt = __LINE__) -> ConstraintMakerEditable { + return self.relatedTo(other, relation: .Equal, file: file, line: line) + } + + public func lessThanOrEqualTo(other: ConstraintRelatableTarget, _ file: String = __FILE__, _ line: UInt = __LINE__) -> ConstraintMakerEditable { + return self.relatedTo(other, relation: .LessThanOrEqual, file: file, line: line) + } + + public func greaterThanOrEqualTo(other: ConstraintRelatableTarget, _ file: String = __FILE__, line: UInt = __LINE__) -> ConstraintMakerEditable { + return self.relatedTo(other, relation: .GreaterThanOrEqual, file: file, line: line) + } + +} diff --git a/Source/ConstraintMultiplierTarget.swift b/Source/ConstraintMultiplierTarget.swift new file mode 100644 index 0000000..7a3b3c9 --- /dev/null +++ b/Source/ConstraintMultiplierTarget.swift @@ -0,0 +1,79 @@ +// +// 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 ConstraintMultiplierTarget { + + var constraintMultiplierTargetValue: CGFloat { get } + +} + +extension Int: ConstraintMultiplierTarget { + + public var constraintMultiplierTargetValue: CGFloat { + return CGFloat(self) + } + +} + +extension UInt: ConstraintMultiplierTarget { + + public var constraintMultiplierTargetValue: CGFloat { + return CGFloat(self) + } + +} + +extension Float: ConstraintMultiplierTarget { + + public var constraintMultiplierTargetValue: CGFloat { + return CGFloat(self) + } + +} + +extension Double: ConstraintMultiplierTarget { + + public var constraintMultiplierTargetValue: CGFloat { + return CGFloat(self) + } + +} + +extension CGFloat: ConstraintMultiplierTarget { + + public var constraintMultiplierTargetValue: CGFloat { + return self + } + +} + +internal func ==(lhs: ConstraintMultiplierTarget, rhs: ConstraintMultiplierTarget) -> Bool { + return lhs.constraintMultiplierTargetValue == rhs.constraintMultiplierTargetValue +} diff --git a/Source/ConstraintOffsetTarget.swift b/Source/ConstraintOffsetTarget.swift new file mode 100644 index 0000000..9ea140d --- /dev/null +++ b/Source/ConstraintOffsetTarget.swift @@ -0,0 +1,47 @@ +// +// 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 ConstraintOffsetTarget: ConstraintConstantTarget { +} + +extension Int: ConstraintOffsetTarget { +} + +extension UInt: ConstraintOffsetTarget { +} + +extension Float: ConstraintOffsetTarget { +} + +extension Double: ConstraintOffsetTarget { +} + +extension CGFloat: ConstraintOffsetTarget { +} diff --git a/Source/ConstraintPriorityTarget.swift b/Source/ConstraintPriorityTarget.swift new file mode 100644 index 0000000..59c6e7a --- /dev/null +++ b/Source/ConstraintPriorityTarget.swift @@ -0,0 +1,79 @@ +// +// 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 ConstraintPriorityTarget { + + var constraintPriorityTargetValue: Float { get } + +} + +extension Int: ConstraintPriorityTarget { + + public var constraintPriorityTargetValue: Float { + return Float(self) + } + +} + +extension UInt: ConstraintPriorityTarget { + + public var constraintPriorityTargetValue: Float { + return Float(self) + } + +} + +extension Float: ConstraintPriorityTarget { + + public var constraintPriorityTargetValue: Float { + return self + } + +} + +extension Double: ConstraintPriorityTarget { + + public var constraintPriorityTargetValue: Float { + return Float(self) + } + +} + +extension CGFloat: ConstraintPriorityTarget { + + public var constraintPriorityTargetValue: Float { + return Float(self) + } + +} + +internal func ==(lhs: ConstraintPriorityTarget, rhs: ConstraintPriorityTarget) -> Bool { + return lhs.constraintPriorityTargetValue == rhs.constraintPriorityTargetValue +} diff --git a/Source/ConstraintRelatableTarget.swift b/Source/ConstraintRelatableTarget.swift new file mode 100644 index 0000000..4d1e37d --- /dev/null +++ b/Source/ConstraintRelatableTarget.swift @@ -0,0 +1,62 @@ +// +// 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 ConstraintRelatableTarget { +} + +extension Int: ConstraintRelatableTarget { +} + +extension UInt: ConstraintRelatableTarget { +} + +extension Float: ConstraintRelatableTarget { +} + +extension Double: ConstraintRelatableTarget { +} + +extension CGFloat: ConstraintRelatableTarget { +} + +extension CGSize: ConstraintRelatableTarget { +} + +extension CGPoint: ConstraintRelatableTarget { +} + +extension ConstraintInsets: ConstraintRelatableTarget { +} + +extension ConstraintItem: ConstraintRelatableTarget { +} + +extension ConstraintView: ConstraintRelatableTarget { +} diff --git a/Source/ConstraintRelation.swift b/Source/ConstraintRelation.swift index f1b1ab2..46295dc 100644 --- a/Source/ConstraintRelation.swift +++ b/Source/ConstraintRelation.swift @@ -1,7 +1,7 @@ // // SnapKit // -// Copyright (c) 2011-2015 SnapKit Team - https://github.com/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 @@ -22,27 +22,27 @@ // THE SOFTWARE. #if os(iOS) || os(tvOS) -import UIKit + import UIKit #else -import AppKit + import AppKit #endif -/** - Used to define `NSLayoutRelation` -*/ + internal enum ConstraintRelation: Int { - case Equal = 1, LessThanOrEqualTo, GreaterThanOrEqualTo + case Equal = 1 + case LessThanOrEqual + case GreaterThanOrEqual internal var layoutRelation: NSLayoutRelation { get { switch(self) { - case .LessThanOrEqualTo: - return .LessThanOrEqual - case .GreaterThanOrEqualTo: - return .GreaterThanOrEqual - default: + case .Equal: return .Equal + case .LessThanOrEqual: + return .LessThanOrEqual + case .GreaterThanOrEqual: + return .GreaterThanOrEqual } } } -} \ No newline at end of file +} diff --git a/Source/ConstraintView+Extensions.swift b/Source/ConstraintView+Extensions.swift new file mode 100644 index 0000000..df8b94e --- /dev/null +++ b/Source/ConstraintView+Extensions.swift @@ -0,0 +1,137 @@ +// +// 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 extension ConstraintView { + + @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_left: ConstraintItem { return self.snp.left } + + @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_top: ConstraintItem { return self.snp.top } + + @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_right: ConstraintItem { return self.snp.right } + + @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_bottom: ConstraintItem { return self.snp.bottom } + + @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_leading: ConstraintItem { return self.snp.leading } + + @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_trailing: ConstraintItem { return self.snp.trailing } + + @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_width: ConstraintItem { return self.snp.width } + + @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_height: ConstraintItem { return self.snp.height } + + @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_centerX: ConstraintItem { return self.snp.centerX } + + @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_centerY: ConstraintItem { return self.snp.centerY } + + @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_baseline: ConstraintItem { return self.snp.baseline } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_firstBaseline: ConstraintItem { return self.snp.firstBaseline } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_leftMargin: ConstraintItem { return self.snp.leftMargin } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_topMargin: ConstraintItem { return self.snp.topMargin } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_rightMargin: ConstraintItem { return self.snp.rightMargin } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_bottomMargin: ConstraintItem { return self.snp.bottomMargin } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_leadingMargin: ConstraintItem { return self.snp.leadingMargin } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_trailingMargin: ConstraintItem { return self.snp.trailingMargin } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_centerXWithinMargins: ConstraintItem { return self.snp.centerXWithinMargins } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_centerYWithinMargins: ConstraintItem { return self.snp.centerYWithinMargins } + + @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_edges: ConstraintItem { return self.snp.edges } + + @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_size: ConstraintItem { return self.snp.size } + + @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_center: ConstraintItem { return self.snp.center } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_margins: ConstraintItem { return self.snp.margins } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var snp_centerWithinMargins: ConstraintItem { return self.snp.centerWithinMargins } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public func snp_prepareConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) -> [Constraint] { + return self.snp.prepareConstraints(closure: closure) + } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public func snp_makeConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { + self.snp.makeConstraints(closure: closure) + } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public func snp_remakeConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { + self.snp.remakeConstraints(closure: closure) + } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public func snp_updateConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { + self.snp.updateConstraints(closure: closure) + } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public func snp_removeConstraints() { + self.snp.removeConstraints() + } + + public var snp: ConstraintViewDSL { + return ConstraintViewDSL(view: self) + } + +} diff --git a/Source/ConstraintView.swift b/Source/ConstraintView.swift new file mode 100644 index 0000000..6ff8a76 --- /dev/null +++ b/Source/ConstraintView.swift @@ -0,0 +1,35 @@ +// +// 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 + + +#if os(iOS) || os(tvOS) + public typealias ConstraintView = UIView +#else + public typealias ConstraintView = NSView +#endif diff --git a/Source/ConstraintViewController+Extensions.swift b/Source/ConstraintViewController+Extensions.swift new file mode 100644 index 0000000..580012e --- /dev/null +++ b/Source/ConstraintViewController+Extensions.swift @@ -0,0 +1,56 @@ +// +// 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 + + + public extension ConstraintViewController { + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var topLayoutGuideTop: ConstraintItem { + return self.snp.topLayoutGuideTop + } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var topLayoutGuideBottom: ConstraintItem { + return self.snp.topLayoutGuideBottom + } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var bottomLayoutGuideTop: ConstraintItem { + return self.snp.bottomLayoutGuideTop + } + + @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + public var bottomLayoutGuideBottom: ConstraintItem { + return self.snp.bottomLayoutGuideBottom + } + + public var snp: ConstraintViewControllerDSL { + return ConstraintViewControllerDSL(viewController: self) + } + + } + +#endif diff --git a/Source/ConstraintViewController.swift b/Source/ConstraintViewController.swift new file mode 100644 index 0000000..9346efa --- /dev/null +++ b/Source/ConstraintViewController.swift @@ -0,0 +1,35 @@ +// +// 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 + + +#if os(iOS) || os(tvOS) + public typealias ConstraintViewController = UIViewController +#else + public typealias ConstraintViewController = NSViewController +#endif diff --git a/Source/ConstraintViewControllerDSL.swift b/Source/ConstraintViewControllerDSL.swift new file mode 100644 index 0000000..b632c99 --- /dev/null +++ b/Source/ConstraintViewControllerDSL.swift @@ -0,0 +1,58 @@ +// +// 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 + + + public struct ConstraintViewControllerDSL { + + @available(iOS 7.0, *) + public var topLayoutGuideTop: ConstraintItem { + return ConstraintItem(target: self.viewController.topLayoutGuide, attributes: ConstraintAttributes.Top) + } + + @available(iOS 7.0, *) + public var topLayoutGuideBottom: ConstraintItem { + return ConstraintItem(target: self.viewController.topLayoutGuide, attributes: ConstraintAttributes.Bottom) + } + + @available(iOS 7.0, *) + public var bottomLayoutGuideTop: ConstraintItem { + return ConstraintItem(target: self.viewController.bottomLayoutGuide, attributes: ConstraintAttributes.Top) + } + + @available(iOS 7.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 + } + + } + +#endif diff --git a/Source/ConstraintViewDSL.swift b/Source/ConstraintViewDSL.swift new file mode 100644 index 0000000..d248f8a --- /dev/null +++ b/Source/ConstraintViewDSL.swift @@ -0,0 +1,196 @@ +// +// 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 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) + } + + public var baseline: ConstraintItem { + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Baseline) + } + + @available(iOS 8.0, *) + 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 func prepareConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) -> [Constraint] { + return ConstraintMaker.prepareConstraints(view: self.view, closure: closure) + } + + public func makeConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { + ConstraintMaker.makeConstraints(view: self.view, closure: closure) + } + + public func remakeConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { + ConstraintMaker.remakeConstraints(view: self.view, closure: closure) + } + + public func updateConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { + ConstraintMaker.updateConstraints(view: self.view, closure: closure) + } + + public func removeConstraints() { + 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) + } + } + + internal let view: ConstraintView + + internal init(view: ConstraintView) { + self.view = view + } + + internal var installedLayoutConstraints: [LayoutConstraint] { + return objc_getAssociatedObject(self.view, &installedLayoutConstraintsKey) as? [LayoutConstraint] ?? [] + } + + internal func appendInstalledLayoutConstraints(layoutConstraints: [LayoutConstraint]) { + var newValue = self.installedLayoutConstraints + newValue += layoutConstraints + objc_setAssociatedObject(self.view, &installedLayoutConstraintsKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + } + + internal func removeInstalledLayoutConstraints(layoutConstraints: [LayoutConstraint]) { + let newValue = self.installedLayoutConstraints.filter { !layoutConstraints.contains($0) } + objc_setAssociatedObject(self.view, &installedLayoutConstraintsKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + } +} + +private var labelKey: UInt8 = 0 +private var installedLayoutConstraintsKey: UInt8 = 0 diff --git a/Source/Debugging.swift b/Source/Debugging.swift index 75e3acf..f7f6b8e 100644 --- a/Source/Debugging.swift +++ b/Source/Debugging.swift @@ -1,7 +1,7 @@ // // SnapKit // -// Copyright (c) 2011-2015 SnapKit Team - https://github.com/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 @@ -22,41 +22,13 @@ // THE SOFTWARE. #if os(iOS) || os(tvOS) -import UIKit + import UIKit #else -import AppKit + import AppKit #endif -/** - Used to allow adding a snp_label to a View for debugging purposes -*/ -public extension View { - - public var snp_label: String? { - get { - return objc_getAssociatedObject(self, &labelKey) as? String - } - set { - objc_setAssociatedObject(self, &labelKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_COPY_NONATOMIC) - } - } - -} - -/** - Used to allow adding a snp_label to a LayoutConstraint for debugging purposes -*/ public extension LayoutConstraint { - public var snp_label: String? { - get { - return objc_getAssociatedObject(self, &labelKey) as? String - } - set { - objc_setAssociatedObject(self, &labelKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_COPY_NONATOMIC) - } - } - override public var description: String { var description = "<" @@ -64,17 +36,17 @@ public extension LayoutConstraint { description += " \(descriptionForObject(self.firstItem))" if self.firstAttribute != .NotAnAttribute { - description += ".\(self.firstAttribute.snp_description)" + description += ".\(descriptionForAttribute(self.firstAttribute))" } - description += " \(self.relation.snp_description)" + description += " \(descriptionForRelation(self.relation))" if let secondItem: AnyObject = self.secondItem { description += " \(descriptionForObject(secondItem))" } if self.secondAttribute != .NotAnAttribute { - description += ".\(self.secondAttribute.snp_description)" + description += ".\(descriptionForAttribute(self.secondAttribute))" } if self.multiplier != 1.0 { @@ -100,57 +72,19 @@ public extension LayoutConstraint { return description } - internal var snp_makerFile: String? { - return self.snp_constraint?.makerLocation.file - } - - internal var snp_makerLine: UInt? { - return self.snp_constraint?.makerLocation.line - } - } -private var labelKey = "" - -private func descriptionForObject(object: AnyObject) -> String { - let pointerDescription = NSString(format: "%p", ObjectIdentifier(object).uintValue) - var desc = "" - - desc += object.dynamicType.description() - - if let object = object as? View { - desc += ":\(object.snp_label ?? pointerDescription)" - } else if let object = object as? LayoutConstraint { - desc += ":\(object.snp_label ?? pointerDescription)" - } else { - desc += ":\(pointerDescription)" +private func descriptionForRelation(relation: NSLayoutRelation) -> String { + switch relation { + case .Equal: return "==" + case .GreaterThanOrEqual: return ">=" + case .LessThanOrEqual: return "<=" } - - if let object = object as? LayoutConstraint, let file = object.snp_makerFile, let line = object.snp_makerLine { - desc += "@\(file)#\(line)" - } - - desc += "" - return desc } -private extension NSLayoutRelation { - - private var snp_description: String { - switch self { - case .Equal: return "==" - case .GreaterThanOrEqual: return ">=" - case .LessThanOrEqual: return "<=" - } - } - -} - -private extension NSLayoutAttribute { - - private var snp_description: String { - #if os(iOS) || os(tvOS) - switch self { +private func descriptionForAttribute(attribute: NSLayoutAttribute) -> String { + #if os(iOS) || os(tvOS) + switch attribute { case .NotAnAttribute: return "notAnAttribute" case .Top: return "top" case .Left: return "left" @@ -173,8 +107,8 @@ private extension NSLayoutAttribute { case .CenterXWithinMargins: return "centerXWithinMargins" case .CenterYWithinMargins: return "centerYWithinMargins" } - #else - switch self { + #else + switch attribute { case .NotAnAttribute: return "notAnAttribute" case .Top: return "top" case .Left: return "left" @@ -189,8 +123,27 @@ private extension NSLayoutAttribute { case .Baseline: return "baseline" default: return "default" } - #endif - + #endif +} + +private func descriptionForObject(object: AnyObject) -> String { + let pointerDescription = NSString(format: "%p", ObjectIdentifier(object).uintValue) + var desc = "" + + desc += object.dynamicType.description() + + if let object = object as? ConstraintView { + desc += ":\(object.snp.label ?? pointerDescription)" + } else if let object = object as? LayoutConstraint { + desc += ":\(object.label ?? pointerDescription)" + } else { + desc += ":\(pointerDescription)" } -} + if let object = object as? LayoutConstraint, let file = object.constraint?.sourceLocation.0, let line = object.constraint?.sourceLocation.1 { + desc += "@\((file as NSString).lastPathComponent)#\(line)" + } + + desc += "" + return desc +} \ No newline at end of file diff --git a/Source/LayoutConstraint.swift b/Source/LayoutConstraint.swift index 87aaad9..0bdf281 100644 --- a/Source/LayoutConstraint.swift +++ b/Source/LayoutConstraint.swift @@ -1,7 +1,7 @@ // // SnapKit // -// Copyright (c) 2011-2015 SnapKit Team - https://github.com/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 @@ -22,45 +22,28 @@ // THE SOFTWARE. #if os(iOS) || os(tvOS) -import UIKit + import UIKit #else -import AppKit + import AppKit #endif -/** - Used to add extra information to the actual `NSLayoutConstraint`'s that will UIKit/AppKit will utilize -*/ + public class LayoutConstraint: NSLayoutConstraint { - internal var snp_constraint: Constraint? = nil + internal var constraint: Constraint? = nil + public var label: String? = nil - public var snp_location: SourceLocation? { - return snp_constraint?.location - } } -internal func ==(left: LayoutConstraint, right: LayoutConstraint) -> Bool { - if left.firstItem !== right.firstItem { - return false - } - if left.secondItem !== right.secondItem { - return false - } - if left.firstAttribute != right.firstAttribute { - return false - } - if left.secondAttribute != right.secondAttribute { - return false - } - if left.relation != right.relation { - return false - } - if left.priority != right.priority { - return false - } - if left.multiplier != right.multiplier { +internal func ==(lhs: LayoutConstraint, rhs: LayoutConstraint) -> Bool { + guard lhs.firstItem === rhs.firstItem && + lhs.secondItem === rhs.secondItem && + lhs.firstAttribute == rhs.firstAttribute && + lhs.secondAttribute == rhs.secondAttribute && + lhs.relation == rhs.relation && + lhs.priority == rhs.priority && + lhs.multiplier == rhs.multiplier else { return false } return true } - diff --git a/Source/View+SnapKit.swift b/Source/View+SnapKit.swift deleted file mode 100644 index 6b2cd51..0000000 --- a/Source/View+SnapKit.swift +++ /dev/null @@ -1,183 +0,0 @@ -// -// SnapKit -// -// Copyright (c) 2011-2015 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 -public typealias View = UIView -#else -import AppKit -public typealias View = NSView -#endif - -/** - Used to expose public API on views -*/ -public extension View { - - /// left edge - public var snp_left: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Left) } - - /// top edge - public var snp_top: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Top) } - - /// right edge - public var snp_right: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Right) } - - /// bottom edge - public var snp_bottom: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Bottom) } - - /// leading edge - public var snp_leading: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Leading) } - - /// trailing edge - public var snp_trailing: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Trailing) } - - /// width dimension - public var snp_width: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Width) } - - /// height dimension - public var snp_height: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Height) } - - /// centerX position - public var snp_centerX: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterX) } - - /// centerY position - public var snp_centerY: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterY) } - - /// baseline position - public var snp_baseline: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Baseline) } - - /// first baseline position - @available(iOS 8.0, *) - public var snp_firstBaseline: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.FirstBaseline) } - - /// left margin - @available(iOS 8.0, *) - public var snp_leftMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.LeftMargin) } - - /// right margin - @available(iOS 8.0, *) - public var snp_rightMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.RightMargin) } - - /// top margin - @available(iOS 8.0, *) - public var snp_topMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.TopMargin) } - - /// bottom margin - @available(iOS 8.0, *) - public var snp_bottomMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.BottomMargin) } - - /// leading margin - @available(iOS 8.0, *) - public var snp_leadingMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.LeadingMargin) } - - /// trailing margin - @available(iOS 8.0, *) - public var snp_trailingMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.TrailingMargin) } - - /// centerX within margins - @available(iOS 8.0, *) - public var snp_centerXWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterXWithinMargins) } - - /// centerY within margins - @available(iOS 8.0, *) - public var snp_centerYWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterYWithinMargins) } - - // top + left + bottom + right edges - public var snp_edges: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Edges) } - - // width + height dimensions - public var snp_size: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Size) } - - // centerX + centerY positions - public var snp_center: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Center) } - - // top + left + bottom + right margins - @available(iOS 8.0, *) - public var snp_margins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Margins) } - - // centerX + centerY within margins - @available(iOS 8.0, *) - public var snp_centerWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterWithinMargins) } - - /** - Prepares constraints with a `ConstraintMaker` and returns the made constraints but does not install them. - - :param: closure that will be passed the `ConstraintMaker` to make the constraints with - - :returns: the constraints made - */ - public func snp_prepareConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] { - return ConstraintMaker.prepareConstraints(view: self, location: SourceLocation(file: file, line: line), closure: closure) - } - - /** - Makes constraints with a `ConstraintMaker` and installs them along side any previous made constraints. - - :param: closure that will be passed the `ConstraintMaker` to make the constraints with - */ - public func snp_makeConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> Void { - ConstraintMaker.makeConstraints(view: self, location: SourceLocation(file: file, line: line), closure: closure) - } - - /** - Updates constraints with a `ConstraintMaker` that will replace existing constraints that match and install new ones. - - For constraints to match only the constant can be updated. - - :param: closure that will be passed the `ConstraintMaker` to update the constraints with - */ - public func snp_updateConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> Void { - ConstraintMaker.updateConstraints(view: self, location: SourceLocation(file: file, line: line), closure: closure) - } - - /** - Remakes constraints with a `ConstraintMaker` that will first remove all previously made constraints and make and install new ones. - - :param: closure that will be passed the `ConstraintMaker` to remake the constraints with - */ - public func snp_remakeConstraints(file: String = __FILE__, line: UInt = __LINE__, @noescape closure: (make: ConstraintMaker) -> Void) -> Void { - ConstraintMaker.remakeConstraints(view: self, location: SourceLocation(file: file, line: line), closure: closure) - } - - /** - Removes all previously made constraints. - */ - public func snp_removeConstraints() { - ConstraintMaker.removeConstraints(view: self) - } - - internal var snp_installedLayoutConstraints: [LayoutConstraint] { - get { - if let constraints = objc_getAssociatedObject(self, &installedLayoutConstraintsKey) as? [LayoutConstraint] { - return constraints - } - return [] - } - set { - objc_setAssociatedObject(self, &installedLayoutConstraintsKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) - } - } -} - -private var installedLayoutConstraintsKey = "" diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 9749fda..c5791d0 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -29,202 +29,4 @@ class SnapKitTests: XCTestCase { super.tearDown() } - func testLayoutGuideConstraints() { - #if os(iOS) || os(tvOS) - let vc = UIViewController() - vc.view = UIView(frame: CGRectMake(0, 0, 300, 300)) - - vc.view.addSubview(self.container) - - self.container.snp_makeConstraints { (make) -> Void in - make.top.equalTo(vc.snp_topLayoutGuideBottom) - make.bottom.equalTo(vc.snp_bottomLayoutGuideTop) - } - - XCTAssertEqual(vc.view.snp_constraints.count, 6, "Should have 6 constraints installed") - #endif - } - - func testMakeConstraints() { - let v1 = View() - let v2 = View() - self.container.addSubview(v1) - self.container.addSubview(v2) - - v1.snp_makeConstraints { (make) -> Void in - make.top.equalTo(v2.snp_top).offset(50) - make.left.equalTo(v2.snp_top).offset(50) - return - } - - XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed") - - v2.snp_makeConstraints { (make) -> Void in - make.edges.equalTo(v1) - return - } - - XCTAssertEqual(self.container.snp_constraints.count, 6, "Should have 6 constraints installed") - - } - - func testUpdateConstraints() { - let v1 = View() - let v2 = View() - self.container.addSubview(v1) - self.container.addSubview(v2) - - v1.snp_makeConstraints { (make) -> Void in - make.top.equalTo(v2.snp_top).offset(50) - make.left.equalTo(v2.snp_top).offset(50) - return - } - - XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed") - - v1.snp_updateConstraints { (make) -> Void in - make.top.equalTo(v2.snp_top).offset(15) - return - } - - XCTAssertEqual(self.container.snp_constraints.count, 2, "Should still have 2 constraints installed") - - } - - func testRemakeConstraints() { - let v1 = View() - let v2 = View() - self.container.addSubview(v1) - self.container.addSubview(v2) - - v1.snp_makeConstraints { (make) -> Void in - make.top.equalTo(v2.snp_top).offset(50) - make.left.equalTo(v2.snp_top).offset(50) - return - } - - XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed") - - v1.snp_remakeConstraints { (make) -> Void in - make.edges.equalTo(v2) - return - } - - XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints installed") - - } - - func testRemoveConstraints() { - let v1 = View() - let v2 = View() - self.container.addSubview(v1) - self.container.addSubview(v2) - - v1.snp_makeConstraints { (make) -> Void in - make.top.equalTo(v2.snp_top).offset(50) - make.left.equalTo(v2.snp_top).offset(50) - return - } - - XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed") - - v1.snp_removeConstraints() - - XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed") - - } - - func testPrepareConstraints() { - let v1 = View() - let v2 = View() - self.container.addSubview(v1) - self.container.addSubview(v2) - - let constraints = v1.snp_prepareConstraints { (make) -> Void in - make.edges.equalTo(v2) - return - } - - XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed") - - for constraint in constraints { - constraint.install() - } - - XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints installed") - - for constraint in constraints { - constraint.uninstall() - } - - XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed") - - } - - func testReinstallConstraints() { - let v1 = View() - let v2 = View() - self.container.addSubview(v1) - self.container.addSubview(v2) - - let constraints = v1.snp_prepareConstraints { (make) -> Void in - make.edges.equalTo(v2) - return - } - - - XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed") - - for constraint in constraints { - constraint.install() - } - - XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints installed") - - for constraint in constraints { - constraint.install() - } - - XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 0 constraints installed") - } - - func testActivateDeactivateConstraints() { - let v1 = View() - let v2 = View() - self.container.addSubview(v1) - self.container.addSubview(v2) - - var c1: Constraint? = nil - var c2: Constraint? = nil - - v1.snp_prepareConstraints { (make) -> Void in - c1 = make.top.equalTo(v2.snp_top).offset(50).constraint - c2 = make.left.equalTo(v2.snp_top).offset(50).constraint - return - } - - XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints") - - c1?.activate() - c2?.activate() - - XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints") - - c1?.deactivate() - c2?.deactivate() - - XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints") - - c1?.uninstall() - c2?.uninstall() - - XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints") - - c1?.activate() - c2?.activate() - - XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints") - - } - } From c5ddeffb0c86047620a6983791c8f9b33c284d79 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Tue, 26 Jan 2016 23:55:36 +1300 Subject: [PATCH 02/58] Updated Changelog --- CHANGELOG.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7575ac..e983537 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,20 @@ CHANGELOG ======= -# 0.19.0 - January 21 2015 +# 0.20.0-alpha1 - January 26 2016 -* Improved `.insets()` for `width` and `height` #183 +** SnapKit 0.20.0 ** is a complete re-write to take advantage of modern Swift as well as +clean up the API. As such please use with caution and check your apps thoroughly + +* All APIs are now accessed via `.snp.*` rather than `.snp_*`. For example you now do `view.snp.makeConstraints {…}` +* Debugging output has been improved to show exact file/line number from which the broken constraint was created. This is an improvement on existing functionality that showed only the file/line number for the make closure. +* `.inset()` will no longer take `CGPoint` or `CGSize` as input +* `.offset()` will no longer take `CGPoint`, `CGSize`, `EdgeInsets` as input +* Exceptions thrown during constraint creation have been replaced with `fatalError` with better output. + +# 0.19.0 - January 21 2016 + +* Improved `.inset()` for `width` and `height` #183 * Added Carthage tvOS support #179 * Added Package.swift #175 * Codesign is set to Distribution on Release #181 From ce3bb65b73fea8886df78efcde6ab80747155cca Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Wed, 27 Jan 2016 00:00:26 +1300 Subject: [PATCH 03/58] Updated readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 031dcb2..f49428d 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,12 @@ import SnapKit class MyViewController: UIViewController { lazy var box = UIView() - + override func viewDidLoad() { super.viewDidLoad() - + self.view.addSubview(box) - box.snp_makeConstraints { (make) -> Void in + box.snp.makeConstraints { (make) -> Void in make.width.height.equalTo(50) make.center.equalTo(self.view) } From d2f259ec5f2e6372996676a0c9e575238edc72f2 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Thu, 19 May 2016 16:54:19 +1200 Subject: [PATCH 04/58] Bump deprecation notices versioning --- Source/ConstraintView+Extensions.swift | 60 +++++++++---------- .../ConstraintViewController+Extensions.swift | 8 +-- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Source/ConstraintView+Extensions.swift b/Source/ConstraintView+Extensions.swift index df8b94e..4775e07 100644 --- a/Source/ConstraintView+Extensions.swift +++ b/Source/ConstraintView+Extensions.swift @@ -30,102 +30,102 @@ public extension ConstraintView { - @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_left: ConstraintItem { return self.snp.left } - @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_top: ConstraintItem { return self.snp.top } - @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_right: ConstraintItem { return self.snp.right } - @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_bottom: ConstraintItem { return self.snp.bottom } - @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_leading: ConstraintItem { return self.snp.leading } - @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_trailing: ConstraintItem { return self.snp.trailing } - @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_width: ConstraintItem { return self.snp.width } - @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_height: ConstraintItem { return self.snp.height } - @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_centerX: ConstraintItem { return self.snp.centerX } - @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_centerY: ConstraintItem { return self.snp.centerY } - @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_baseline: ConstraintItem { return self.snp.baseline } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_firstBaseline: ConstraintItem { return self.snp.firstBaseline } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_leftMargin: ConstraintItem { return self.snp.leftMargin } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_topMargin: ConstraintItem { return self.snp.topMargin } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_rightMargin: ConstraintItem { return self.snp.rightMargin } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_bottomMargin: ConstraintItem { return self.snp.bottomMargin } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_leadingMargin: ConstraintItem { return self.snp.leadingMargin } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_trailingMargin: ConstraintItem { return self.snp.trailingMargin } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_centerXWithinMargins: ConstraintItem { return self.snp.centerXWithinMargins } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_centerYWithinMargins: ConstraintItem { return self.snp.centerYWithinMargins } - @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_edges: ConstraintItem { return self.snp.edges } - @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_size: ConstraintItem { return self.snp.size } - @available(*, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_center: ConstraintItem { return self.snp.center } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_margins: ConstraintItem { return self.snp.margins } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var snp_centerWithinMargins: ConstraintItem { return self.snp.centerWithinMargins } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public func snp_prepareConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) -> [Constraint] { return self.snp.prepareConstraints(closure: closure) } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public func snp_makeConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { self.snp.makeConstraints(closure: closure) } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public func snp_remakeConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { self.snp.remakeConstraints(closure: closure) } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public func snp_updateConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { self.snp.updateConstraints(closure: closure) } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public func snp_removeConstraints() { self.snp.removeConstraints() } diff --git a/Source/ConstraintViewController+Extensions.swift b/Source/ConstraintViewController+Extensions.swift index 580012e..06b59f2 100644 --- a/Source/ConstraintViewController+Extensions.swift +++ b/Source/ConstraintViewController+Extensions.swift @@ -27,22 +27,22 @@ public extension ConstraintViewController { - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var topLayoutGuideTop: ConstraintItem { return self.snp.topLayoutGuideTop } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var topLayoutGuideBottom: ConstraintItem { return self.snp.topLayoutGuideBottom } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var bottomLayoutGuideTop: ConstraintItem { return self.snp.bottomLayoutGuideTop } - @available(iOS, deprecated=0.20.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") public var bottomLayoutGuideBottom: ConstraintItem { return self.snp.bottomLayoutGuideBottom } From c2eeb3b8d8aa2713a4599ed6dd7cec15f0e0ae21 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Thu, 19 May 2016 16:56:41 +1200 Subject: [PATCH 05/58] Updated Podspec --- SnapKit.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SnapKit.podspec b/SnapKit.podspec index 2e63a5b..cf622d7 100644 --- a/SnapKit.podspec +++ b/SnapKit.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = 'SnapKit' - s.version = '0.19.0' + s.version = '0.30.0.beta1' s.license = 'MIT' s.summary = 'Harness the power of auto layout with a simplified, chainable, and compile time safe syntax.' s.homepage = 'https://github.com/SnapKit/SnapKit' s.authors = { 'Robert Payne' => 'robertpayne@me.com' } s.social_media_url = 'http://twitter.com/robertjpayne' - s.source = { :git => 'https://github.com/SnapKit/SnapKit.git', :tag => '0.19.0' } + s.source = { :git => 'https://github.com/SnapKit/SnapKit.git', :tag => '0.30.0.beta1' } s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.10' From a837c94c8b601efaf41da3694713149c6484b69b Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Thu, 19 May 2016 16:58:01 +1200 Subject: [PATCH 06/58] Updated Changelog --- CHANGELOG.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e983537..44f7dee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ CHANGELOG ======= -# 0.20.0-alpha1 - January 26 2016 +# 0.30.0.beta1 - May 19 2016 ** SnapKit 0.20.0 ** is a complete re-write to take advantage of modern Swift as well as clean up the API. As such please use with caution and check your apps thoroughly @@ -12,9 +12,23 @@ clean up the API. As such please use with caution and check your apps thoroughly * `.offset()` will no longer take `CGPoint`, `CGSize`, `EdgeInsets` as input * Exceptions thrown during constraint creation have been replaced with `fatalError` with better output. +# 0.21.0 - May 11 2016 + +* Added `equalToSuperview()` convenience +* Enabled app extension API for tvOS and OSX + +# 0.20.0 - March 25 2016 + +* Swift 2.2 Support +* Added a `labeled("Hello")` to constraint chain to label your constraints for debugging output. + +# 0.19.1 - January 26 2016 + +* Rebased from 0.16.0 with only desired commits to resolve many unexpected issues + # 0.19.0 - January 21 2016 -* Improved `.inset()` for `width` and `height` #183 +* Improved `.insets()` for `width` and `height` #183 * Added Carthage tvOS support #179 * Added Package.swift #175 * Codesign is set to Distribution on Release #181 @@ -54,4 +68,4 @@ clean up the API. As such please use with caution and check your apps thoroughly * Re-worked some internal API to allow for future updates * Added `snp_prepareConstraints -> [Constraint]` which allows pre-building of constraints -* Added a fatal error to `and` when it is used after relation has been set +* Added a fatal error to `and` when it is used after relation has been set \ No newline at end of file From 1071951dc9adf17a3eb060c309a6255dafaee0e1 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Thu, 19 May 2016 17:02:10 +1200 Subject: [PATCH 07/58] Updated changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44f7dee..4d9c2b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ CHANGELOG # 0.30.0.beta1 - May 19 2016 -** SnapKit 0.20.0 ** is a complete re-write to take advantage of modern Swift as well as +** SnapKit 0.30.0 ** is a complete re-write to take advantage of modern Swift as well as clean up the API. As such please use with caution and check your apps thoroughly * All APIs are now accessed via `.snp.*` rather than `.snp_*`. For example you now do `view.snp.makeConstraints {…}` From f785886d3aebb9175407753d5bb1d3472ead1b38 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Thu, 19 May 2016 17:02:15 +1200 Subject: [PATCH 08/58] Fix deprecated APIs --- Source/ConstraintMakerRelatable.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/ConstraintMakerRelatable.swift b/Source/ConstraintMakerRelatable.swift index e5d92cc..093583b 100644 --- a/Source/ConstraintMakerRelatable.swift +++ b/Source/ConstraintMakerRelatable.swift @@ -67,15 +67,15 @@ public class ConstraintMakerRelatable { return editable } - public func equalTo(other: ConstraintRelatableTarget, _ file: String = __FILE__, _ line: UInt = __LINE__) -> ConstraintMakerEditable { + public func equalTo(other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { return self.relatedTo(other, relation: .Equal, file: file, line: line) } - public func lessThanOrEqualTo(other: ConstraintRelatableTarget, _ file: String = __FILE__, _ line: UInt = __LINE__) -> ConstraintMakerEditable { + public func lessThanOrEqualTo(other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { return self.relatedTo(other, relation: .LessThanOrEqual, file: file, line: line) } - public func greaterThanOrEqualTo(other: ConstraintRelatableTarget, _ file: String = __FILE__, line: UInt = __LINE__) -> ConstraintMakerEditable { + public func greaterThanOrEqualTo(other: ConstraintRelatableTarget, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable { return self.relatedTo(other, relation: .GreaterThanOrEqual, file: file, line: line) } From 8355410d923d14a6ba6770b8c53a908023a5d708 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Wed, 15 Jun 2016 13:49:49 +1200 Subject: [PATCH 09/58] Swift 3.0 Migration --- SnapKit.podspec | 4 +- SnapKit.xcodeproj/project.pbxproj | 9 +++ Source/Constraint.swift | 30 ++++---- Source/ConstraintAttributes.swift | 54 +++++++-------- Source/ConstraintConfig.swift | 2 +- Source/ConstraintConstantTarget.swift | 36 +++++----- Source/ConstraintMaker.swift | 12 ++-- Source/ConstraintMakerEditable.swift | 8 +-- Source/ConstraintMakerPriortizable.swift | 2 +- Source/ConstraintMakerRelatable.swift | 14 ++-- Source/ConstraintMultiplierTarget.swift | 4 -- Source/ConstraintPriorityTarget.swift | 4 -- Source/ConstraintRelation.swift | 18 ++--- Source/ConstraintView+Extensions.swift | 68 +++++++++---------- .../ConstraintViewController+Extensions.swift | 8 +-- Source/ConstraintViewDSL.swift | 12 ++-- Source/Debugging.swift | 64 ++++++++--------- 17 files changed, 175 insertions(+), 174 deletions(-) diff --git a/SnapKit.podspec b/SnapKit.podspec index cf622d7..9c15617 100644 --- a/SnapKit.podspec +++ b/SnapKit.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = 'SnapKit' - s.version = '0.30.0.beta1' + s.version = '0.40.0.beta1' s.license = 'MIT' s.summary = 'Harness the power of auto layout with a simplified, chainable, and compile time safe syntax.' s.homepage = 'https://github.com/SnapKit/SnapKit' s.authors = { 'Robert Payne' => 'robertpayne@me.com' } s.social_media_url = 'http://twitter.com/robertjpayne' - s.source = { :git => 'https://github.com/SnapKit/SnapKit.git', :tag => '0.30.0.beta1' } + s.source = { :git => 'https://github.com/SnapKit/SnapKit.git', :tag => '0.40.0.beta1' } s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.10' diff --git a/SnapKit.xcodeproj/project.pbxproj b/SnapKit.xcodeproj/project.pbxproj index 920c9cd..e22c0fe 100644 --- a/SnapKit.xcodeproj/project.pbxproj +++ b/SnapKit.xcodeproj/project.pbxproj @@ -495,15 +495,18 @@ TargetAttributes = { 537DCE911C35CC8800B5B899 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; 537DCEAE1C35D90A00B5B899 = { CreatedOnToolsVersion = 7.2; }; EEBCC9D719CC627D0083B827 = { CreatedOnToolsVersion = 6.0; + LastSwiftMigration = 0800; }; EEBCC9E119CC627D0083B827 = { CreatedOnToolsVersion = 6.0; + LastSwiftMigration = 0800; }; EECDB3791AC0C9D4006BBC11 = { CreatedOnToolsVersion = 6.2; @@ -741,6 +744,7 @@ SDKROOT = appletvos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; @@ -767,6 +771,7 @@ PRODUCT_NAME = SnapKit; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; @@ -903,6 +908,7 @@ SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -925,6 +931,7 @@ PRODUCT_NAME = SnapKit; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -938,6 +945,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -949,6 +957,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 21d42c7..2b14487 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -80,7 +80,7 @@ public class Constraint { // MARK: Internal - internal func installIfNeeded(updateExisting updateExisting: Bool = false) -> [NSLayoutConstraint] { + internal func installIfNeeded(updateExisting: Bool = false) -> [NSLayoutConstraint] { let installOnView: ConstraintView? if let view = self.to.view { @@ -88,7 +88,7 @@ public class Constraint { fatalError("Cannot Install Constraint. No common superview. (\(self.sourceLocation.0), \(self.sourceLocation.1))") } installOnView = closestSuperview - } else if self.from.attributes.isSubsetOf(ConstraintAttributes.Width + ConstraintAttributes.Height) { + } else if self.from.attributes.isSubset(of: ConstraintAttributes.Width + ConstraintAttributes.Height) { installOnView = self.from.view } else { guard let superview = self.from.view?.superview else { @@ -128,7 +128,7 @@ public class Constraint { #else var layoutTo: AnyObject? = self.to.view #endif - if layoutTo == nil && layoutToAttribute != .Width && layoutToAttribute != .Height { + if layoutTo == nil && layoutToAttribute != .width && layoutToAttribute != .height { layoutTo = installOnView } @@ -157,7 +157,7 @@ public class Constraint { if updateExisting { // get existing constraints for this view - let existingLayoutConstraints = layoutFrom.snp.installedLayoutConstraints.reverse() + let existingLayoutConstraints = layoutFrom.snp.installedLayoutConstraints.reversed() // array that will contain only new layout constraints to keep var newLayoutConstraintsToKeep = [LayoutConstraint]() @@ -197,15 +197,15 @@ public class Constraint { installOnView?.addConstraints(newLayoutConstraints) } #else - NSLayoutConstraint.activateConstraints(newLayoutConstraints) + NSLayoutConstraint.activate(newLayoutConstraints) #endif // set install info - self.installInfo = ConstraintInstallInfo(view: installOnView, layoutConstraints: NSHashTable.weakObjectsHashTable()) + self.installInfo = ConstraintInstallInfo(view: installOnView, layoutConstraints: HashTable.weakObjects()) // store which layout constraints are installed for this constraint for layoutConstraint in newLayoutConstraints { - self.installInfo!.layoutConstraints.addObject(layoutConstraint) + self.installInfo!.layoutConstraints.add(layoutConstraint) } // store the layout constraints against the layout from view @@ -231,7 +231,7 @@ public class Constraint { installedOnView.removeConstraints(installedLayoutConstraints) } #else - NSLayoutConstraint.deactivateConstraints(installedLayoutConstraints) + NSLayoutConstraint.deactivate(installedLayoutConstraints) #endif // remove the constraints from the from item view @@ -255,7 +255,7 @@ public class Constraint { return } - NSLayoutConstraint.activateConstraints(layoutConstraints) + NSLayoutConstraint.activate(layoutConstraints) } internal func deactivateIfNeeded() { @@ -270,7 +270,7 @@ public class Constraint { return } - NSLayoutConstraint.deactivateConstraints(layoutConstraints) + NSLayoutConstraint.deactivate(layoutConstraints) } } @@ -278,16 +278,16 @@ public class Constraint { private final class ConstraintInstallInfo { private weak var view: ConstraintView? = nil - private let layoutConstraints: NSHashTable + private let layoutConstraints: HashTable - private init(view: ConstraintView?, layoutConstraints: NSHashTable) { + private init(view: ConstraintView?, layoutConstraints: HashTable) { self.view = view self.layoutConstraints = layoutConstraints } } -private func closestCommonSuperviewFromView(fromView: ConstraintView?, toView: ConstraintView?) -> ConstraintView? { +private func closestCommonSuperviewFromView(_ fromView: ConstraintView?, toView: ConstraintView?) -> ConstraintView? { var views = Set() var fromView = fromView var toView = toView @@ -315,6 +315,6 @@ private func ==(lhs: Constraint, rhs: Constraint) -> Bool { return (lhs.from == rhs.from && lhs.to == rhs.to && lhs.relation == rhs.relation && - lhs.multiplier == rhs.multiplier && - lhs.priority == rhs.priority) + lhs.multiplier.constraintMultiplierTargetValue == rhs.multiplier.constraintMultiplierTargetValue && + lhs.priority.constraintPriorityTargetValue == rhs.priority.constraintPriorityTargetValue) } diff --git a/Source/ConstraintAttributes.swift b/Source/ConstraintAttributes.swift index 6308856..89d7eab 100644 --- a/Source/ConstraintAttributes.swift +++ b/Source/ConstraintAttributes.swift @@ -28,7 +28,7 @@ #endif -internal struct ConstraintAttributes: OptionSetType, BooleanType { +internal struct ConstraintAttributes: OptionSet, Boolean { internal init(rawValue: UInt) { self.rawValue = rawValue @@ -46,8 +46,8 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType { internal var boolValue: Bool { return self.rawValue != 0 } internal func toRaw() -> UInt { return self.rawValue } - internal static func fromRaw(raw: UInt) -> ConstraintAttributes? { return self.init(raw) } - internal static func fromMask(raw: UInt) -> ConstraintAttributes { return self.init(raw) } + internal static func fromRaw(_ raw: UInt) -> ConstraintAttributes? { return self.init(raw) } + internal static func fromMask(_ raw: UInt) -> ConstraintAttributes { return self.init(raw) } // normal @@ -98,37 +98,37 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType { internal var layoutAttributes:[NSLayoutAttribute] { var attrs = [NSLayoutAttribute]() if (self.contains(ConstraintAttributes.Left)) { - attrs.append(.Left) + attrs.append(.left) } if (self.contains(ConstraintAttributes.Top)) { - attrs.append(.Top) + attrs.append(.top) } if (self.contains(ConstraintAttributes.Right)) { - attrs.append(.Right) + attrs.append(.right) } if (self.contains(ConstraintAttributes.Bottom)) { - attrs.append(.Bottom) + attrs.append(.bottom) } if (self.contains(ConstraintAttributes.Leading)) { - attrs.append(.Leading) + attrs.append(.leading) } if (self.contains(ConstraintAttributes.Trailing)) { - attrs.append(.Trailing) + attrs.append(.trailing) } if (self.contains(ConstraintAttributes.Width)) { - attrs.append(.Width) + attrs.append(.width) } if (self.contains(ConstraintAttributes.Height)) { - attrs.append(.Height) + attrs.append(.height) } if (self.contains(ConstraintAttributes.CenterX)) { - attrs.append(.CenterX) + attrs.append(.centerX) } if (self.contains(ConstraintAttributes.CenterY)) { - attrs.append(.CenterY) + attrs.append(.centerY) } if (self.contains(ConstraintAttributes.Baseline)) { - attrs.append(.Baseline) + attrs.append(.lastBaseline) } #if os(iOS) || os(tvOS) @@ -138,31 +138,31 @@ internal struct ConstraintAttributes: OptionSetType, BooleanType { } #endif if (self.contains(ConstraintAttributes.FirstBaseline)) { - attrs.append(.FirstBaseline) + attrs.append(.firstBaseline) } if (self.contains(ConstraintAttributes.LeftMargin)) { - attrs.append(.LeftMargin) + attrs.append(.leftMargin) } if (self.contains(ConstraintAttributes.RightMargin)) { - attrs.append(.RightMargin) + attrs.append(.rightMargin) } if (self.contains(ConstraintAttributes.TopMargin)) { - attrs.append(.TopMargin) + attrs.append(.topMargin) } if (self.contains(ConstraintAttributes.BottomMargin)) { - attrs.append(.BottomMargin) + attrs.append(.bottomMargin) } if (self.contains(ConstraintAttributes.LeadingMargin)) { - attrs.append(.LeadingMargin) + attrs.append(.leadingMargin) } if (self.contains(ConstraintAttributes.TrailingMargin)) { - attrs.append(.TrailingMargin) + attrs.append(.trailingMargin) } if (self.contains(ConstraintAttributes.CenterXWithinMargins)) { - attrs.append(.CenterXWithinMargins) + attrs.append(.centerXWithinMargins) } if (self.contains(ConstraintAttributes.CenterYWithinMargins)) { - attrs.append(.CenterYWithinMargins) + attrs.append(.centerYWithinMargins) } #endif @@ -174,12 +174,12 @@ internal func + (left: ConstraintAttributes, right: ConstraintAttributes) -> Con return left.union(right) } -internal func +=(inout left: ConstraintAttributes, right: ConstraintAttributes) { - left.unionInPlace(right) +internal func +=(left: inout ConstraintAttributes, right: ConstraintAttributes) { + left.formUnion(right) } -internal func -=(inout left: ConstraintAttributes, right: ConstraintAttributes) { - left.subtractInPlace(right) +internal func -=(left: inout ConstraintAttributes, right: ConstraintAttributes) { + left.subtract(right) } internal func ==(left: ConstraintAttributes, right: ConstraintAttributes) -> Bool { diff --git a/Source/ConstraintConfig.swift b/Source/ConstraintConfig.swift index 3b58816..2746b7d 100644 --- a/Source/ConstraintConfig.swift +++ b/Source/ConstraintConfig.swift @@ -32,6 +32,6 @@ public struct ConstraintConfig { - public static var interfaceLayoutDirection: ConstraintInterfaceLayoutDirection = .LeftToRight + public static var interfaceLayoutDirection: ConstraintInterfaceLayoutDirection = .leftToRight } diff --git a/Source/ConstraintConstantTarget.swift b/Source/ConstraintConstantTarget.swift index 69dec3f..6e9b2f1 100644 --- a/Source/ConstraintConstantTarget.swift +++ b/Source/ConstraintConstantTarget.swift @@ -42,7 +42,7 @@ extension ConstraintInsets: ConstraintConstantTarget { extension ConstraintConstantTarget { - internal func layoutConstantForLayoutAttribute(layoutAttribute: NSLayoutAttribute) -> CGFloat { + internal func layoutConstantForLayoutAttribute(_ layoutAttribute: NSLayoutAttribute) -> CGFloat { if let value = self as? Float { return CGFloat(value) } @@ -64,9 +64,9 @@ extension ConstraintConstantTarget { } if let value = self as? CGSize { - if layoutAttribute == .Width { + if layoutAttribute == .width { return value.width - } else if layoutAttribute == .Height { + } else if layoutAttribute == .height { return value.height } else { return 0.0 @@ -77,11 +77,11 @@ extension ConstraintConstantTarget { if let value = self as? CGPoint { #if os(iOS) || os(tvOS) switch layoutAttribute { - case .Left, .Right, .Leading, .Trailing, .CenterX, .LeftMargin, .RightMargin, .LeadingMargin, .TrailingMargin, .CenterXWithinMargins: + case .left, .right, .leading, .trailing, .centerX, .leftMargin, .rightMargin, .leadingMargin, .trailingMargin, .centerXWithinMargins: return value.x - case .Top, .Bottom, .CenterY, .TopMargin, .BottomMargin, .CenterYWithinMargins, .Baseline, .FirstBaseline: + case .top, .bottom, .centerY, .topMargin, .bottomMargin, .centerYWithinMargins, .lastBaseline, .firstBaseline: return value.y - case .Width, .Height, .NotAnAttribute: + case .width, .height, .notAnAttribute: return 0.0 } #else @@ -99,23 +99,23 @@ extension ConstraintConstantTarget { if let value = self as? ConstraintInsets { #if os(iOS) || os(tvOS) switch layoutAttribute { - case .Left, .LeftMargin, .CenterX, .CenterXWithinMargins: + case .left, .leftMargin, .centerX, .centerXWithinMargins: return value.left - case .Top, .TopMargin, .CenterY, .CenterYWithinMargins, .Baseline, .FirstBaseline: + case .top, .topMargin, .centerY, .centerYWithinMargins, .lastBaseline, .firstBaseline: return value.top - case .Right, .RightMargin: + case .right, .rightMargin: return value.right - case .Bottom, .BottomMargin: + case .bottom, .bottomMargin: return value.bottom - case .Leading, .LeadingMargin: - return (ConstraintConfig.interfaceLayoutDirection == .LeftToRight) ? value.left : -value.right - case .Trailing, .TrailingMargin: - return (ConstraintConfig.interfaceLayoutDirection == .LeftToRight) ? value.right : -value.left - case .Width: + case .leading, .leadingMargin: + return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : -value.right + case .trailing, .trailingMargin: + return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.right : -value.left + case .width: return -value.left + value.right - case .Height: + case .height: return -value.top + value.bottom - case .NotAnAttribute: + case .notAnAttribute: return 0.0 } #else @@ -145,4 +145,4 @@ extension ConstraintConstantTarget { return 0.0 } -} \ No newline at end of file +} diff --git a/Source/ConstraintMaker.swift b/Source/ConstraintMaker.swift index 3ece978..c8616f6 100644 --- a/Source/ConstraintMaker.swift +++ b/Source/ConstraintMaker.swift @@ -129,13 +129,13 @@ public class ConstraintMaker { self.view.translatesAutoresizingMaskIntoConstraints = false } - internal func makeExtendableWithAttributes(attributes: ConstraintAttributes) -> ConstraintMakerExtendable { + internal func makeExtendableWithAttributes(_ attributes: ConstraintAttributes) -> ConstraintMakerExtendable { let description = ConstraintDescription(view: self.view, attributes: attributes) self.descriptions.append(description) return ConstraintMakerExtendable(description) } - internal static func prepareConstraints(view view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] { + internal static func prepareConstraints(view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] { let maker = ConstraintMaker(view: view) closure(make: maker) let constraints = maker.descriptions @@ -145,7 +145,7 @@ public class ConstraintMaker { return constraints } - internal static func makeConstraints(view view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { + internal static func makeConstraints(view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { let maker = ConstraintMaker(view: view) closure(make: maker) let constraints = maker.descriptions @@ -157,12 +157,12 @@ public class ConstraintMaker { } } - internal static func remakeConstraints(view view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { + internal static func remakeConstraints(view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { self.removeConstraints(view: view) self.makeConstraints(view: view, closure: closure) } - internal static func updateConstraints(view view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { + internal static func updateConstraints(view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { let maker = ConstraintMaker(view: view) closure(make: maker) let constraints = maker.descriptions @@ -174,7 +174,7 @@ public class ConstraintMaker { } } - internal static func removeConstraints(view view: ConstraintView) { + internal static func removeConstraints(view: ConstraintView) { } diff --git a/Source/ConstraintMakerEditable.swift b/Source/ConstraintMakerEditable.swift index 2f6c37b..dcccdf1 100644 --- a/Source/ConstraintMakerEditable.swift +++ b/Source/ConstraintMakerEditable.swift @@ -30,21 +30,21 @@ public class ConstraintMakerEditable: ConstraintMakerPriortizable { - public func multipliedBy(amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable { + public func multipliedBy(_ amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable { self.description.multiplier = amount return self } - public func dividedBy(amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable { + public func dividedBy(_ amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable { return self.multipliedBy(1.0 / amount.constraintMultiplierTargetValue) } - public func offset(amount: ConstraintOffsetTarget) -> ConstraintMakerEditable { + public func offset(_ amount: ConstraintOffsetTarget) -> ConstraintMakerEditable { self.description.constant = amount return self } - public func inset(amount: ConstraintInsetTarget) -> ConstraintMakerEditable { + public func inset(_ amount: ConstraintInsetTarget) -> ConstraintMakerEditable { let insets: ConstraintInsets if let amount = amount as? ConstraintInsets { diff --git a/Source/ConstraintMakerPriortizable.swift b/Source/ConstraintMakerPriortizable.swift index 81bec09..355faef 100644 --- a/Source/ConstraintMakerPriortizable.swift +++ b/Source/ConstraintMakerPriortizable.swift @@ -30,7 +30,7 @@ public class ConstraintMakerPriortizable: ConstraintMakerFinalizable { - public func priority(amount: ConstraintPriorityTarget) -> ConstraintMakerFinalizable { + public func priority(_ amount: ConstraintPriorityTarget) -> ConstraintMakerFinalizable { self.description.priority = amount return self } diff --git a/Source/ConstraintMakerRelatable.swift b/Source/ConstraintMakerRelatable.swift index 093583b..c0ba2c9 100644 --- a/Source/ConstraintMakerRelatable.swift +++ b/Source/ConstraintMakerRelatable.swift @@ -36,7 +36,7 @@ public class ConstraintMakerRelatable { self.description = description } - internal func relatedTo(other: ConstraintRelatableTarget, relation: ConstraintRelation, file: String, line: UInt) -> ConstraintMakerEditable { + internal func relatedTo(_ other: ConstraintRelatableTarget, relation: ConstraintRelation, file: String, line: UInt) -> ConstraintMakerEditable { let related: ConstraintItem let constant: ConstraintConstantTarget @@ -67,16 +67,16 @@ public class ConstraintMakerRelatable { return editable } - public func equalTo(other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { - return self.relatedTo(other, relation: .Equal, file: file, line: line) + public func equalTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { + return self.relatedTo(other, relation: .equal, file: file, line: line) } - public func lessThanOrEqualTo(other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { - return self.relatedTo(other, relation: .LessThanOrEqual, file: file, line: line) + public func lessThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { + return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line) } - public func greaterThanOrEqualTo(other: ConstraintRelatableTarget, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable { - return self.relatedTo(other, relation: .GreaterThanOrEqual, file: file, line: line) + public func greaterThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable { + return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line) } } diff --git a/Source/ConstraintMultiplierTarget.swift b/Source/ConstraintMultiplierTarget.swift index 7a3b3c9..6fecd33 100644 --- a/Source/ConstraintMultiplierTarget.swift +++ b/Source/ConstraintMultiplierTarget.swift @@ -73,7 +73,3 @@ extension CGFloat: ConstraintMultiplierTarget { } } - -internal func ==(lhs: ConstraintMultiplierTarget, rhs: ConstraintMultiplierTarget) -> Bool { - return lhs.constraintMultiplierTargetValue == rhs.constraintMultiplierTargetValue -} diff --git a/Source/ConstraintPriorityTarget.swift b/Source/ConstraintPriorityTarget.swift index 59c6e7a..eb32f79 100644 --- a/Source/ConstraintPriorityTarget.swift +++ b/Source/ConstraintPriorityTarget.swift @@ -73,7 +73,3 @@ extension CGFloat: ConstraintPriorityTarget { } } - -internal func ==(lhs: ConstraintPriorityTarget, rhs: ConstraintPriorityTarget) -> Bool { - return lhs.constraintPriorityTargetValue == rhs.constraintPriorityTargetValue -} diff --git a/Source/ConstraintRelation.swift b/Source/ConstraintRelation.swift index 46295dc..48afbfc 100644 --- a/Source/ConstraintRelation.swift +++ b/Source/ConstraintRelation.swift @@ -29,19 +29,19 @@ internal enum ConstraintRelation: Int { - case Equal = 1 - case LessThanOrEqual - case GreaterThanOrEqual + case equal = 1 + case lessThanOrEqual + case greaterThanOrEqual internal var layoutRelation: NSLayoutRelation { get { switch(self) { - case .Equal: - return .Equal - case .LessThanOrEqual: - return .LessThanOrEqual - case .GreaterThanOrEqual: - return .GreaterThanOrEqual + case .equal: + return .equal + case .lessThanOrEqual: + return .lessThanOrEqual + case .greaterThanOrEqual: + return .greaterThanOrEqual } } } diff --git a/Source/ConstraintView+Extensions.swift b/Source/ConstraintView+Extensions.swift index 4775e07..a371448 100644 --- a/Source/ConstraintView+Extensions.swift +++ b/Source/ConstraintView+Extensions.swift @@ -30,102 +30,102 @@ public extension ConstraintView { - @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_left: ConstraintItem { return self.snp.left } - @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_top: ConstraintItem { return self.snp.top } - @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_right: ConstraintItem { return self.snp.right } - @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_bottom: ConstraintItem { return self.snp.bottom } - @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_leading: ConstraintItem { return self.snp.leading } - @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_trailing: ConstraintItem { return self.snp.trailing } - @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_width: ConstraintItem { return self.snp.width } - @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_height: ConstraintItem { return self.snp.height } - @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_centerX: ConstraintItem { return self.snp.centerX } - @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_centerY: ConstraintItem { return self.snp.centerY } - @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_baseline: ConstraintItem { return self.snp.baseline } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_firstBaseline: ConstraintItem { return self.snp.firstBaseline } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_leftMargin: ConstraintItem { return self.snp.leftMargin } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_topMargin: ConstraintItem { return self.snp.topMargin } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_rightMargin: ConstraintItem { return self.snp.rightMargin } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_bottomMargin: ConstraintItem { return self.snp.bottomMargin } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_leadingMargin: ConstraintItem { return self.snp.leadingMargin } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_trailingMargin: ConstraintItem { return self.snp.trailingMargin } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_centerXWithinMargins: ConstraintItem { return self.snp.centerXWithinMargins } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_centerYWithinMargins: ConstraintItem { return self.snp.centerYWithinMargins } - @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_edges: ConstraintItem { return self.snp.edges } - @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_size: ConstraintItem { return self.snp.size } - @available(*, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_center: ConstraintItem { return self.snp.center } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_margins: ConstraintItem { return self.snp.margins } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var snp_centerWithinMargins: ConstraintItem { return self.snp.centerWithinMargins } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") - public func snp_prepareConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) -> [Constraint] { + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + public func snp_prepareConstraints(@noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] { return self.snp.prepareConstraints(closure: closure) } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") - public func snp_makeConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + public func snp_makeConstraints(@noescape closure: (make: ConstraintMaker) -> Void) { self.snp.makeConstraints(closure: closure) } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") - public func snp_remakeConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + public func snp_remakeConstraints(@noescape closure: (make: ConstraintMaker) -> Void) { self.snp.remakeConstraints(closure: closure) } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") - public func snp_updateConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + public func snp_updateConstraints(@noescape closure: (make: ConstraintMaker) -> Void) { self.snp.updateConstraints(closure: closure) } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public func snp_removeConstraints() { self.snp.removeConstraints() } diff --git a/Source/ConstraintViewController+Extensions.swift b/Source/ConstraintViewController+Extensions.swift index 06b59f2..f609f8f 100644 --- a/Source/ConstraintViewController+Extensions.swift +++ b/Source/ConstraintViewController+Extensions.swift @@ -27,22 +27,22 @@ public extension ConstraintViewController { - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var topLayoutGuideTop: ConstraintItem { return self.snp.topLayoutGuideTop } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var topLayoutGuideBottom: ConstraintItem { return self.snp.topLayoutGuideBottom } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var bottomLayoutGuideTop: ConstraintItem { return self.snp.bottomLayoutGuideTop } - @available(iOS, deprecated=0.30.0, message="Please use newer snp.* syntax.") + @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") public var bottomLayoutGuideBottom: ConstraintItem { return self.snp.bottomLayoutGuideBottom } diff --git a/Source/ConstraintViewDSL.swift b/Source/ConstraintViewDSL.swift index d248f8a..31b9174 100644 --- a/Source/ConstraintViewDSL.swift +++ b/Source/ConstraintViewDSL.swift @@ -141,19 +141,19 @@ public struct ConstraintViewDSL { return ConstraintItem(target: self.view, attributes: ConstraintAttributes.CenterWithinMargins) } - public func prepareConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) -> [Constraint] { + public func prepareConstraints(closure: @noescape (make: ConstraintMaker) -> Void) -> [Constraint] { return ConstraintMaker.prepareConstraints(view: self.view, closure: closure) } - public func makeConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { + public func makeConstraints(closure: @noescape (make: ConstraintMaker) -> Void) { ConstraintMaker.makeConstraints(view: self.view, closure: closure) } - public func remakeConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { + public func remakeConstraints(closure: @noescape (make: ConstraintMaker) -> Void) { ConstraintMaker.remakeConstraints(view: self.view, closure: closure) } - public func updateConstraints(@noescape closure closure: (make: ConstraintMaker) -> Void) { + public func updateConstraints(closure: @noescape (make: ConstraintMaker) -> Void) { ConstraintMaker.updateConstraints(view: self.view, closure: closure) } @@ -180,13 +180,13 @@ public struct ConstraintViewDSL { return objc_getAssociatedObject(self.view, &installedLayoutConstraintsKey) as? [LayoutConstraint] ?? [] } - internal func appendInstalledLayoutConstraints(layoutConstraints: [LayoutConstraint]) { + internal func appendInstalledLayoutConstraints(_ layoutConstraints: [LayoutConstraint]) { var newValue = self.installedLayoutConstraints newValue += layoutConstraints objc_setAssociatedObject(self.view, &installedLayoutConstraintsKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) } - internal func removeInstalledLayoutConstraints(layoutConstraints: [LayoutConstraint]) { + internal func removeInstalledLayoutConstraints(_ layoutConstraints: [LayoutConstraint]) { let newValue = self.installedLayoutConstraints.filter { !layoutConstraints.contains($0) } objc_setAssociatedObject(self.view, &installedLayoutConstraintsKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) } diff --git a/Source/Debugging.swift b/Source/Debugging.swift index f7f6b8e..c3caae8 100644 --- a/Source/Debugging.swift +++ b/Source/Debugging.swift @@ -35,7 +35,7 @@ public extension LayoutConstraint { description += descriptionForObject(self) description += " \(descriptionForObject(self.firstItem))" - if self.firstAttribute != .NotAnAttribute { + if self.firstAttribute != .notAnAttribute { description += ".\(descriptionForAttribute(self.firstAttribute))" } @@ -45,7 +45,7 @@ public extension LayoutConstraint { description += " \(descriptionForObject(secondItem))" } - if self.secondAttribute != .NotAnAttribute { + if self.secondAttribute != .notAnAttribute { description += ".\(descriptionForAttribute(self.secondAttribute))" } @@ -53,7 +53,7 @@ public extension LayoutConstraint { description += " * \(self.multiplier)" } - if self.secondAttribute == .NotAnAttribute { + if self.secondAttribute == .notAnAttribute { description += " \(self.constant)" } else { if self.constant > 0.0 { @@ -74,38 +74,38 @@ public extension LayoutConstraint { } -private func descriptionForRelation(relation: NSLayoutRelation) -> String { +private func descriptionForRelation(_ relation: NSLayoutRelation) -> String { switch relation { - case .Equal: return "==" - case .GreaterThanOrEqual: return ">=" - case .LessThanOrEqual: return "<=" + case .equal: return "==" + case .greaterThanOrEqual: return ">=" + case .lessThanOrEqual: return "<=" } } -private func descriptionForAttribute(attribute: NSLayoutAttribute) -> String { +private func descriptionForAttribute(_ attribute: NSLayoutAttribute) -> String { #if os(iOS) || os(tvOS) switch attribute { - case .NotAnAttribute: return "notAnAttribute" - case .Top: return "top" - case .Left: return "left" - case .Bottom: return "bottom" - case .Right: return "right" - case .Leading: return "leading" - case .Trailing: return "trailing" - case .Width: return "width" - case .Height: return "height" - case .CenterX: return "centerX" - case .CenterY: return "centerY" - case .Baseline: return "baseline" - case .FirstBaseline: return "firstBaseline" - case .TopMargin: return "topMargin" - case .LeftMargin: return "leftMargin" - case .BottomMargin: return "bottomMargin" - case .RightMargin: return "rightMargin" - case .LeadingMargin: return "leadingMargin" - case .TrailingMargin: return "trailingMargin" - case .CenterXWithinMargins: return "centerXWithinMargins" - case .CenterYWithinMargins: return "centerYWithinMargins" + case .notAnAttribute: return "notAnAttribute" + case .top: return "top" + case .left: return "left" + case .bottom: return "bottom" + case .right: return "right" + case .leading: return "leading" + case .trailing: return "trailing" + case .width: return "width" + case .height: return "height" + case .centerX: return "centerX" + case .centerY: return "centerY" + case .lastBaseline: return "baseline" + case .firstBaseline: return "firstBaseline" + case .topMargin: return "topMargin" + case .leftMargin: return "leftMargin" + case .bottomMargin: return "bottomMargin" + case .rightMargin: return "rightMargin" + case .leadingMargin: return "leadingMargin" + case .trailingMargin: return "trailingMargin" + case .centerXWithinMargins: return "centerXWithinMargins" + case .centerYWithinMargins: return "centerYWithinMargins" } #else switch attribute { @@ -126,8 +126,8 @@ private func descriptionForAttribute(attribute: NSLayoutAttribute) -> String { #endif } -private func descriptionForObject(object: AnyObject) -> String { - let pointerDescription = NSString(format: "%p", ObjectIdentifier(object).uintValue) +private func descriptionForObject(_ object: AnyObject) -> String { + let pointerDescription = NSString(format: "%p", UInt(ObjectIdentifier(object))) var desc = "" desc += object.dynamicType.description() @@ -146,4 +146,4 @@ private func descriptionForObject(object: AnyObject) -> String { desc += "" return desc -} \ No newline at end of file +} From d00444d7d1875e2387487b4d0e3eb83e8bc29720 Mon Sep 17 00:00:00 2001 From: Alex Pawlowski Date: Tue, 28 Jun 2016 15:31:43 +0300 Subject: [PATCH 10/58] Migrated to latest Swift 3.0 syntax and latest macOS Cocoa API --- SnapKit.xcodeproj/project.pbxproj | 10 ++++- .../xcschemes/SnapKit OSX.xcscheme | 10 ++--- .../xcschemes/SnapKit iOS.xcscheme | 10 ++--- .../xcschemes/SnapKit tvOS.xcscheme | 2 +- Source/Constraint.swift | 2 +- Source/ConstraintConstantTarget.swift | 28 ++++++------ Source/ConstraintInsets.swift | 2 +- Source/ConstraintMaker.swift | 12 +++--- Source/ConstraintView+Extensions.swift | 16 +++---- Source/ConstraintViewDSL.swift | 8 ++-- Source/Debugging.swift | 43 ++++++++++++------- 11 files changed, 81 insertions(+), 62 deletions(-) diff --git a/SnapKit.xcodeproj/project.pbxproj b/SnapKit.xcodeproj/project.pbxproj index e22c0fe..b6c1f92 100644 --- a/SnapKit.xcodeproj/project.pbxproj +++ b/SnapKit.xcodeproj/project.pbxproj @@ -490,7 +490,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "SnapKit Team"; TargetAttributes = { 537DCE911C35CC8800B5B899 = { @@ -771,6 +771,7 @@ PRODUCT_NAME = SnapKit; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; @@ -804,6 +805,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TVOS_DEPLOYMENT_TARGET = 9.1; }; name = Release; @@ -831,6 +833,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -875,6 +878,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -931,6 +935,7 @@ PRODUCT_NAME = SnapKit; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -957,6 +962,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; }; name = Release; @@ -1012,6 +1018,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -1044,6 +1051,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; }; name = Release; }; diff --git a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme index 3ffad95..15b42fe 100644 --- a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme +++ b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme @@ -1,6 +1,6 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -66,11 +66,11 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -66,11 +66,11 @@ Void) -> [Constraint] { + internal static func prepareConstraints(view: ConstraintView, closure: @noescape(make: ConstraintMaker) -> Void) -> [Constraint] { let maker = ConstraintMaker(view: view) closure(make: maker) let constraints = maker.descriptions @@ -145,7 +145,7 @@ public class ConstraintMaker { return constraints } - internal static func makeConstraints(view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { + internal static func makeConstraints(view: ConstraintView, closure: @noescape(make: ConstraintMaker) -> Void) { let maker = ConstraintMaker(view: view) closure(make: maker) let constraints = maker.descriptions @@ -153,16 +153,16 @@ public class ConstraintMaker { .filter { $0 != nil } .map { $0! } for constraint in constraints { - constraint.installIfNeeded() + let _ = constraint.installIfNeeded() } } - internal static func remakeConstraints(view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { + internal static func remakeConstraints(view: ConstraintView, closure: @noescape(make: ConstraintMaker) -> Void) { self.removeConstraints(view: view) self.makeConstraints(view: view, closure: closure) } - internal static func updateConstraints(view: ConstraintView, @noescape closure: (make: ConstraintMaker) -> Void) { + internal static func updateConstraints(view: ConstraintView, closure: @noescape(make: ConstraintMaker) -> Void) { let maker = ConstraintMaker(view: view) closure(make: maker) let constraints = maker.descriptions @@ -170,7 +170,7 @@ public class ConstraintMaker { .filter { $0 != nil } .map { $0! } for constraint in constraints { - constraint.installIfNeeded(updateExisting: true) + let _ = constraint.installIfNeeded(updateExisting: true) } } diff --git a/Source/ConstraintView+Extensions.swift b/Source/ConstraintView+Extensions.swift index a371448..cd08dd0 100644 --- a/Source/ConstraintView+Extensions.swift +++ b/Source/ConstraintView+Extensions.swift @@ -106,23 +106,23 @@ public extension ConstraintView { public var snp_centerWithinMargins: ConstraintItem { return self.snp.centerWithinMargins } @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") - public func snp_prepareConstraints(@noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] { - return self.snp.prepareConstraints(closure: closure) + public func snp_prepareConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) -> [Constraint] { + return self.snp.prepareConstraints(closure) } @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") - public func snp_makeConstraints(@noescape closure: (make: ConstraintMaker) -> Void) { - self.snp.makeConstraints(closure: closure) + public func snp_makeConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { + self.snp.makeConstraints(closure) } @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") - public func snp_remakeConstraints(@noescape closure: (make: ConstraintMaker) -> Void) { - self.snp.remakeConstraints(closure: closure) + public func snp_remakeConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { + self.snp.remakeConstraints(closure) } @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") - public func snp_updateConstraints(@noescape closure: (make: ConstraintMaker) -> Void) { - self.snp.updateConstraints(closure: closure) + public func snp_updateConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { + self.snp.updateConstraints(closure) } @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") diff --git a/Source/ConstraintViewDSL.swift b/Source/ConstraintViewDSL.swift index 31b9174..3e85df0 100644 --- a/Source/ConstraintViewDSL.swift +++ b/Source/ConstraintViewDSL.swift @@ -141,19 +141,19 @@ public struct ConstraintViewDSL { return ConstraintItem(target: self.view, attributes: ConstraintAttributes.CenterWithinMargins) } - public func prepareConstraints(closure: @noescape (make: ConstraintMaker) -> Void) -> [Constraint] { + public func prepareConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) -> [Constraint] { return ConstraintMaker.prepareConstraints(view: self.view, closure: closure) } - public func makeConstraints(closure: @noescape (make: ConstraintMaker) -> Void) { + public func makeConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) { ConstraintMaker.makeConstraints(view: self.view, closure: closure) } - public func remakeConstraints(closure: @noescape (make: ConstraintMaker) -> Void) { + public func remakeConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) { ConstraintMaker.remakeConstraints(view: self.view, closure: closure) } - public func updateConstraints(closure: @noescape (make: ConstraintMaker) -> Void) { + public func updateConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) { ConstraintMaker.updateConstraints(view: self.view, closure: closure) } diff --git a/Source/Debugging.swift b/Source/Debugging.swift index c3caae8..e4bec9f 100644 --- a/Source/Debugging.swift +++ b/Source/Debugging.swift @@ -34,14 +34,17 @@ public extension LayoutConstraint { description += descriptionForObject(self) - description += " \(descriptionForObject(self.firstItem))" + if let firstItem = conditionalOptional(from: self.firstItem) { + description += " \(descriptionForObject(firstItem))" + } + if self.firstAttribute != .notAnAttribute { description += ".\(descriptionForAttribute(self.firstAttribute))" } description += " \(descriptionForRelation(self.relation))" - if let secondItem: AnyObject = self.secondItem { + if let secondItem = self.secondItem { description += " \(descriptionForObject(secondItem))" } @@ -96,7 +99,7 @@ private func descriptionForAttribute(_ attribute: NSLayoutAttribute) -> String { case .height: return "height" case .centerX: return "centerX" case .centerY: return "centerY" - case .lastBaseline: return "baseline" + case .lastBaseline: return "lastBaseline" case .firstBaseline: return "firstBaseline" case .topMargin: return "topMargin" case .leftMargin: return "leftMargin" @@ -109,23 +112,31 @@ private func descriptionForAttribute(_ attribute: NSLayoutAttribute) -> String { } #else switch attribute { - case .NotAnAttribute: return "notAnAttribute" - case .Top: return "top" - case .Left: return "left" - case .Bottom: return "bottom" - case .Right: return "right" - case .Leading: return "leading" - case .Trailing: return "trailing" - case .Width: return "width" - case .Height: return "height" - case .CenterX: return "centerX" - case .CenterY: return "centerY" - case .Baseline: return "baseline" - default: return "default" + case .notAnAttribute: return "notAnAttribute" + case .top: return "top" + case .left: return "left" + case .bottom: return "bottom" + case .right: return "right" + case .leading: return "leading" + case .trailing: return "trailing" + case .width: return "width" + case .height: return "height" + case .centerX: return "centerX" + case .centerY: return "centerY" + case .lastBaseline: return "lastBaseline" + case .firstBaseline: return "firstBaseline" } #endif } +private func conditionalOptional(from object: Optional) -> Optional { + return object +} + +private func conditionalOptional(from object: T) -> Optional { + return Optional.some(object) +} + private func descriptionForObject(_ object: AnyObject) -> String { let pointerDescription = NSString(format: "%p", UInt(ObjectIdentifier(object))) var desc = "" From b916d759562396b390898ebbbdc7bae2077d31a5 Mon Sep 17 00:00:00 2001 From: Alex Pawlowski Date: Tue, 28 Jun 2016 15:55:23 +0300 Subject: [PATCH 11/58] Added sensible @discardableResult attributes for ConstraintMaker public functions --- Source/ConstraintMakerEditable.swift | 4 ++++ Source/ConstraintMakerPriortizable.swift | 5 +++++ Source/ConstraintMakerRelatable.swift | 3 +++ 3 files changed, 12 insertions(+) diff --git a/Source/ConstraintMakerEditable.swift b/Source/ConstraintMakerEditable.swift index dcccdf1..8c125e5 100644 --- a/Source/ConstraintMakerEditable.swift +++ b/Source/ConstraintMakerEditable.swift @@ -30,20 +30,24 @@ public class ConstraintMakerEditable: ConstraintMakerPriortizable { + @discardableResult public func multipliedBy(_ amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable { self.description.multiplier = amount return self } + @discardableResult public func dividedBy(_ amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable { return self.multipliedBy(1.0 / amount.constraintMultiplierTargetValue) } + @discardableResult public func offset(_ amount: ConstraintOffsetTarget) -> ConstraintMakerEditable { self.description.constant = amount return self } + @discardableResult public func inset(_ amount: ConstraintInsetTarget) -> ConstraintMakerEditable { let insets: ConstraintInsets diff --git a/Source/ConstraintMakerPriortizable.swift b/Source/ConstraintMakerPriortizable.swift index 355faef..9616a38 100644 --- a/Source/ConstraintMakerPriortizable.swift +++ b/Source/ConstraintMakerPriortizable.swift @@ -30,19 +30,23 @@ public class ConstraintMakerPriortizable: ConstraintMakerFinalizable { + @discardableResult public func priority(_ amount: ConstraintPriorityTarget) -> ConstraintMakerFinalizable { self.description.priority = amount return self } + @discardableResult public func priorityRequired() -> ConstraintMakerFinalizable { return self.priority(1000) } + @discardableResult public func priorityHigh() -> ConstraintMakerFinalizable { return self.priority(750) } + @discardableResult public func priorityMedium() -> ConstraintMakerFinalizable { #if os(iOS) || os(tvOS) return self.priority(500) @@ -51,6 +55,7 @@ public class ConstraintMakerPriortizable: ConstraintMakerFinalizable { #endif } + @discardableResult public func priorityLow() -> ConstraintMakerFinalizable { return self.priority(250) } diff --git a/Source/ConstraintMakerRelatable.swift b/Source/ConstraintMakerRelatable.swift index c0ba2c9..bab6369 100644 --- a/Source/ConstraintMakerRelatable.swift +++ b/Source/ConstraintMakerRelatable.swift @@ -67,14 +67,17 @@ public class ConstraintMakerRelatable { return editable } + @discardableResult public func equalTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { return self.relatedTo(other, relation: .equal, file: file, line: line) } + @discardableResult public func lessThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line) } + @discardableResult public func greaterThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable { return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line) } From adab4b821aa92d0ac33c6e4f6c4bd9219423020c Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Wed, 6 Jul 2016 09:08:14 -0700 Subject: [PATCH 12/58] Deprecate .baseline and migrate to .lastBaseline --- Source/ConstraintViewDSL.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/ConstraintViewDSL.swift b/Source/ConstraintViewDSL.swift index 3e85df0..2a2331d 100644 --- a/Source/ConstraintViewDSL.swift +++ b/Source/ConstraintViewDSL.swift @@ -70,10 +70,15 @@ public struct ConstraintViewDSL { return ConstraintItem(target: self.view, attributes: ConstraintAttributes.CenterY) } + @available(iOS, deprecated:0.30.0, message:"Please use migrated .lastBaseline") public var baseline: ConstraintItem { return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Baseline) } + public var lastBaseline: ConstraintItem { + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Baseline) + } + @available(iOS 8.0, *) public var firstBaseline: ConstraintItem { return ConstraintItem(target: self.view, attributes: ConstraintAttributes.FirstBaseline) From 4f47f13902c0a8bf8e2aaefbbfefe534172a0e3d Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Wed, 6 Jul 2016 09:09:31 -0700 Subject: [PATCH 13/58] Updated podspec --- SnapKit.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SnapKit.podspec b/SnapKit.podspec index 9c15617..019a640 100644 --- a/SnapKit.podspec +++ b/SnapKit.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = 'SnapKit' - s.version = '0.40.0.beta1' + s.version = '0.40.0.beta2' s.license = 'MIT' s.summary = 'Harness the power of auto layout with a simplified, chainable, and compile time safe syntax.' s.homepage = 'https://github.com/SnapKit/SnapKit' s.authors = { 'Robert Payne' => 'robertpayne@me.com' } s.social_media_url = 'http://twitter.com/robertjpayne' - s.source = { :git => 'https://github.com/SnapKit/SnapKit.git', :tag => '0.40.0.beta1' } + s.source = { :git => 'https://github.com/SnapKit/SnapKit.git', :tag => '0.40.0.beta2' } s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.10' From 9f8ad446773e5a075d2a8cd8eac520cfa52c2a41 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Mon, 11 Jul 2016 21:56:23 -0600 Subject: [PATCH 14/58] Add missing remove constraints function content --- Source/ConstraintMaker.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/ConstraintMaker.swift b/Source/ConstraintMaker.swift index 9e4ebc2..746b44b 100644 --- a/Source/ConstraintMaker.swift +++ b/Source/ConstraintMaker.swift @@ -175,7 +175,9 @@ public class ConstraintMaker { } internal static func removeConstraints(view: ConstraintView) { - + for layoutConstraint in view.snp.installedLayoutConstraints { + layoutConstraint.constraint?.uninstall() + } } } From 4715badfa0e1aba30b519e3fd9b04867ae4cbd73 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Tue, 2 Aug 2016 19:56:16 +1200 Subject: [PATCH 15/58] Beta 4 Updates --- Source/Constraint.swift | 22 +++++++++++----------- Source/ConstraintAttributes.swift | 2 +- Source/ConstraintItem.swift | 4 ++-- Source/Debugging.swift | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 90b532e..45f6014 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -201,7 +201,7 @@ public class Constraint { #endif // set install info - self.installInfo = ConstraintInstallInfo(view: installOnView, layoutConstraints: HashTable.weakObjects()) + self.installInfo = ConstraintInstallInfo(view: installOnView, layoutConstraints: NSHashTable.weakObjects()) // store which layout constraints are installed for this constraint for layoutConstraint in newLayoutConstraints { @@ -219,8 +219,8 @@ public class Constraint { self.installInfo = nil } - guard let installedLayoutConstraints = self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint] - where installedLayoutConstraints.count > 0 else { + guard let installedLayoutConstraints = self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint], + installedLayoutConstraints.count > 0 else { return } @@ -250,9 +250,9 @@ public class Constraint { } #endif - guard let layoutConstraints = self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint] - where layoutConstraints.count > 0 else { - return + guard let layoutConstraints = self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint], + layoutConstraints.count > 0 else { + return } NSLayoutConstraint.activate(layoutConstraints) @@ -265,9 +265,9 @@ public class Constraint { } #endif - guard let layoutConstraints = self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint] - where layoutConstraints.count > 0 else { - return + guard let layoutConstraints = self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint], + layoutConstraints.count > 0 else { + return } NSLayoutConstraint.deactivate(layoutConstraints) @@ -278,9 +278,9 @@ public class Constraint { private final class ConstraintInstallInfo { private weak var view: ConstraintView? = nil - private let layoutConstraints: HashTable + private let layoutConstraints: NSHashTable - private init(view: ConstraintView?, layoutConstraints: HashTable) { + private init(view: ConstraintView?, layoutConstraints: NSHashTable) { self.view = view self.layoutConstraints = layoutConstraints } diff --git a/Source/ConstraintAttributes.swift b/Source/ConstraintAttributes.swift index 89d7eab..3c4cf68 100644 --- a/Source/ConstraintAttributes.swift +++ b/Source/ConstraintAttributes.swift @@ -28,7 +28,7 @@ #endif -internal struct ConstraintAttributes: OptionSet, Boolean { +internal struct ConstraintAttributes: OptionSet { internal init(rawValue: UInt) { self.rawValue = rawValue diff --git a/Source/ConstraintItem.swift b/Source/ConstraintItem.swift index 6ff291e..83733b5 100644 --- a/Source/ConstraintItem.swift +++ b/Source/ConstraintItem.swift @@ -56,8 +56,8 @@ public func ==(lhs: ConstraintItem, rhs: ConstraintItem) -> Bool { // must both have valid targets and identical attributes guard let target1 = lhs.target, - let target2 = rhs.target - where target1 === target2 && lhs.attributes == rhs.attributes else { + let target2 = rhs.target, + target1 === target2 && lhs.attributes == rhs.attributes else { return false } diff --git a/Source/Debugging.swift b/Source/Debugging.swift index e4bec9f..ff3a8a2 100644 --- a/Source/Debugging.swift +++ b/Source/Debugging.swift @@ -62,7 +62,7 @@ public extension LayoutConstraint { if self.constant > 0.0 { description += " + \(self.constant)" } else if self.constant < 0.0 { - description += " - \(CGFloat.abs(self.constant))" + description += " - \(abs(self.constant))" } } From 8fc933a5c2cee28b6d6752a58de94ef7efe37a9c Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Wed, 3 Aug 2016 14:39:47 +1200 Subject: [PATCH 16/58] Fix up legacy deployment and availability of APIs --- Source/Constraint.swift | 10 +-- Source/ConstraintView+Extensions.swift | 74 +++++++++++-------- .../ConstraintViewController+Extensions.swift | 8 +- Source/ConstraintViewDSL.swift | 5 +- 4 files changed, 56 insertions(+), 41 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 45f6014..8836ae1 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -192,7 +192,7 @@ public class Constraint { // add constraints #if SNAPKIT_DEPLOYMENT_LEGACY && (os(iOS) || os(tvOS)) if #available(iOS 8.0, *) { - NSLayoutConstraint.activateConstraints(newLayoutConstraints) + NSLayoutConstraint.activate(newLayoutConstraints) } else { installOnView?.addConstraints(newLayoutConstraints) } @@ -226,8 +226,8 @@ public class Constraint { #if SNAPKIT_DEPLOYMENT_LEGACY && !os(OSX) if #available(iOS 8.0, *) { - NSLayoutConstraint.deactivateConstraints(installedLayoutConstraints) - } else if let installedOnView = installInfo.view { + NSLayoutConstraint.deactivate(installedLayoutConstraints) + } else if let installedOnView = installInfo?.view { installedOnView.removeConstraints(installedLayoutConstraints) } #else @@ -240,12 +240,12 @@ public class Constraint { internal func activateIfNeeded() { guard self.installInfo != nil else { - let _ = self.installIfNeeded() + _ = self.installIfNeeded() return } #if SNAPKIT_DEPLOYMENT_LEGACY guard #available(iOS 8.0, OSX 10.10, *) else { - self.installIfNeeded() + _ = self.installIfNeeded() return } #endif diff --git a/Source/ConstraintView+Extensions.swift b/Source/ConstraintView+Extensions.swift index cd08dd0..7f78824 100644 --- a/Source/ConstraintView+Extensions.swift +++ b/Source/ConstraintView+Extensions.swift @@ -30,102 +30,116 @@ public extension ConstraintView { - @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var snp_left: ConstraintItem { return self.snp.left } - @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var snp_top: ConstraintItem { return self.snp.top } - @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var snp_right: ConstraintItem { return self.snp.right } - @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var snp_bottom: ConstraintItem { return self.snp.bottom } - @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var snp_leading: ConstraintItem { return self.snp.leading } - @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var snp_trailing: ConstraintItem { return self.snp.trailing } - @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var snp_width: ConstraintItem { return self.snp.width } - @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var snp_height: ConstraintItem { return self.snp.height } - @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var snp_centerX: ConstraintItem { return self.snp.centerX } - @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var snp_centerY: ConstraintItem { return self.snp.centerY } - @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var snp_baseline: ConstraintItem { return self.snp.baseline } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + public var snp_lastBaseline: ConstraintItem { return self.snp.lastBaseline } + + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS 8.0, OSX 10.11, *) public var snp_firstBaseline: ConstraintItem { return self.snp.firstBaseline } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS 8.0, OSX 10.11, *) public var snp_leftMargin: ConstraintItem { return self.snp.leftMargin } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS 8.0, *) public var snp_topMargin: ConstraintItem { return self.snp.topMargin } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS 8.0, *) public var snp_rightMargin: ConstraintItem { return self.snp.rightMargin } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS 8.0, *) public var snp_bottomMargin: ConstraintItem { return self.snp.bottomMargin } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS 8.0, *) public var snp_leadingMargin: ConstraintItem { return self.snp.leadingMargin } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS 8.0, *) public var snp_trailingMargin: ConstraintItem { return self.snp.trailingMargin } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS 8.0, *) public var snp_centerXWithinMargins: ConstraintItem { return self.snp.centerXWithinMargins } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS 8.0, *) public var snp_centerYWithinMargins: ConstraintItem { return self.snp.centerYWithinMargins } - @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var snp_edges: ConstraintItem { return self.snp.edges } - @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var snp_size: ConstraintItem { return self.snp.size } - @available(*, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var snp_center: ConstraintItem { return self.snp.center } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS 8.0, *) public var snp_margins: ConstraintItem { return self.snp.margins } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS 8.0, *) public var snp_centerWithinMargins: ConstraintItem { return self.snp.centerWithinMargins } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public func snp_prepareConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) -> [Constraint] { return self.snp.prepareConstraints(closure) } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public func snp_makeConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { self.snp.makeConstraints(closure) } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public func snp_remakeConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { self.snp.remakeConstraints(closure) } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public func snp_updateConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { self.snp.updateConstraints(closure) } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public func snp_removeConstraints() { self.snp.removeConstraints() } diff --git a/Source/ConstraintViewController+Extensions.swift b/Source/ConstraintViewController+Extensions.swift index f609f8f..c7b18fe 100644 --- a/Source/ConstraintViewController+Extensions.swift +++ b/Source/ConstraintViewController+Extensions.swift @@ -27,22 +27,22 @@ public extension ConstraintViewController { - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var topLayoutGuideTop: ConstraintItem { return self.snp.topLayoutGuideTop } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var topLayoutGuideBottom: ConstraintItem { return self.snp.topLayoutGuideBottom } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var bottomLayoutGuideTop: ConstraintItem { return self.snp.bottomLayoutGuideTop } - @available(iOS, deprecated:0.30.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") public var bottomLayoutGuideBottom: ConstraintItem { return self.snp.bottomLayoutGuideBottom } diff --git a/Source/ConstraintViewDSL.swift b/Source/ConstraintViewDSL.swift index 2a2331d..86f0bf9 100644 --- a/Source/ConstraintViewDSL.swift +++ b/Source/ConstraintViewDSL.swift @@ -70,16 +70,17 @@ public struct ConstraintViewDSL { return ConstraintItem(target: self.view, attributes: ConstraintAttributes.CenterY) } - @available(iOS, deprecated:0.30.0, message:"Please use migrated .lastBaseline") + @available(*, deprecated:0.40.0, message:"Please use migrated .lastBaseline") public var baseline: ConstraintItem { return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Baseline) } + @available(iOS 8.0, OSX 10.11, *) public var lastBaseline: ConstraintItem { return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Baseline) } - @available(iOS 8.0, *) + @available(iOS 8.0, OSX 10.11, *) public var firstBaseline: ConstraintItem { return ConstraintItem(target: self.view, attributes: ConstraintAttributes.FirstBaseline) } From 5b5720d435a0bc781201e118ec4c02e774e056d6 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Thu, 4 Aug 2016 10:27:05 +1200 Subject: [PATCH 17/58] Tweak build settings --- SnapKit.xcodeproj/project.pbxproj | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/SnapKit.xcodeproj/project.pbxproj b/SnapKit.xcodeproj/project.pbxproj index b6c1f92..4cbdd63 100644 --- a/SnapKit.xcodeproj/project.pbxproj +++ b/SnapKit.xcodeproj/project.pbxproj @@ -847,11 +847,12 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -886,9 +887,10 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 8.0; - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -912,7 +914,6 @@ SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -936,7 +937,6 @@ SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -985,7 +985,6 @@ INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SnapKit; SDKROOT = macosx; @@ -1012,7 +1011,6 @@ INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SnapKit; SDKROOT = macosx; From 8b85ac86d3c92a5ca7c8890024fecfdbf3b8a136 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Thu, 4 Aug 2016 10:27:15 +1200 Subject: [PATCH 18/58] Fix missing availability macro --- Source/ConstraintView+Extensions.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/ConstraintView+Extensions.swift b/Source/ConstraintView+Extensions.swift index 7f78824..0e89a32 100644 --- a/Source/ConstraintView+Extensions.swift +++ b/Source/ConstraintView+Extensions.swift @@ -64,6 +64,7 @@ public extension ConstraintView { public var snp_baseline: ConstraintItem { return self.snp.baseline } @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS 8.0, OSX 10.11, *) public var snp_lastBaseline: ConstraintItem { return self.snp.lastBaseline } @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") From 200b34149263c90eb8b4bd2b44509c7060f882c0 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Thu, 4 Aug 2016 10:27:26 +1200 Subject: [PATCH 19/58] Add content hugging / compression resistance shortcuts --- Source/ConstraintViewDSL.swift | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Source/ConstraintViewDSL.swift b/Source/ConstraintViewDSL.swift index 86f0bf9..35a4c39 100644 --- a/Source/ConstraintViewDSL.swift +++ b/Source/ConstraintViewDSL.swift @@ -176,6 +176,42 @@ public struct ConstraintViewDSL { } } + public var contentHuggingHorizontalPriority: Float { + get { + return self.view.contentHuggingPriority(for: .horizontal) + } + set { + self.view.setContentHuggingPriority(newValue, for: .horizontal) + } + } + + public var contentHuggingVerticalPriority: Float { + get { + return self.view.contentHuggingPriority(for: .vertical) + } + set { + self.view.setContentHuggingPriority(newValue, for: .vertical) + } + } + + public var contentCompressionResistanceHorizontalPriority: Float { + get { + return self.view.contentCompressionResistancePriority(for: .horizontal) + } + set { + self.view.setContentHuggingPriority(newValue, for: .horizontal) + } + } + + public var contentCompressionResistanceVerticalPriority: Float { + get { + return self.view.contentCompressionResistancePriority(for: .vertical) + } + set { + self.view.setContentCompressionResistancePriority(newValue, for: .vertical) + } + } + internal let view: ConstraintView internal init(view: ConstraintView) { From e713b9da5b5c8edd711647592821b1ff53112cdb Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Thu, 4 Aug 2016 10:46:25 +1200 Subject: [PATCH 20/58] =?UTF-8?q?Add=20API=E2=80=99s=20for=20updating=20of?= =?UTF-8?q?fset/inset/priorty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Constraint.swift | 43 +++++++++++++++++++++++++-- Source/ConstraintConstantTarget.swift | 11 ++++--- Source/ConstraintInsetTarget.swift | 26 ++++++++++++++++ Source/ConstraintMakerEditable.swift | 23 ++------------ Source/ConstraintOffsetTarget.swift | 22 ++++++++++++++ 5 files changed, 95 insertions(+), 30 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 8836ae1..eb6387a 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -36,8 +36,16 @@ public class Constraint { private let to: ConstraintItem private let relation: ConstraintRelation private let multiplier: ConstraintMultiplierTarget - private var constant: ConstraintConstantTarget - private var priority: ConstraintPriorityTarget + private var constant: ConstraintConstantTarget { + didSet { + self.updateConstantAndPriorityIfNeeded() + } + } + private var priority: ConstraintPriorityTarget { + didSet { + self.updateConstantAndPriorityIfNeeded() + } + } private var installInfo: ConstraintInstallInfo? = nil // MARK: Initialization @@ -78,8 +86,37 @@ public class Constraint { self.deactivateIfNeeded() } + @discardableResult + public func update(offset: ConstraintOffsetTarget) -> Constraint { + self.constant = offset.constraintOffsetTargetValue + return self + } + + @discardableResult + public func update(inset: ConstraintInsetTarget) -> Constraint { + self.constant = inset.constraintInsetTargetValue + return self + } + + @discardableResult + public func update(priority: ConstraintPriorityTarget) -> Constraint { + self.priority = priority.constraintPriorityTargetValue + return self + } + // MARK: Internal + internal func updateConstantAndPriorityIfNeeded() { + guard let installInfo = self.installInfo else { + return + } + for layoutConstraint in installInfo.layoutConstraints.allObjects as! [LayoutConstraint] { + let attribute = (layoutConstraint.secondAttribute == .notAnAttribute) ? layoutConstraint.firstAttribute : layoutConstraint.secondAttribute + layoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: attribute) + layoutConstraint.priority = self.priority.constraintPriorityTargetValue + } + } + internal func installIfNeeded(updateExisting: Bool = false) -> [NSLayoutConstraint] { let installOnView: ConstraintView? @@ -120,7 +157,7 @@ public class Constraint { let layoutToAttribute = (layoutToAttributes.count > 0) ? layoutToAttributes[0] : layoutFromAttribute // get layout constant - let layoutConstant: CGFloat = self.constant.layoutConstantForLayoutAttribute(layoutToAttribute) + let layoutConstant: CGFloat = self.constant.constraintConstantTargetValueFor(layoutAttribute: layoutToAttribute) // get layout to #if os(iOS) || os(tvOS) diff --git a/Source/ConstraintConstantTarget.swift b/Source/ConstraintConstantTarget.swift index 00e07e3..40ed274 100644 --- a/Source/ConstraintConstantTarget.swift +++ b/Source/ConstraintConstantTarget.swift @@ -42,7 +42,11 @@ extension ConstraintInsets: ConstraintConstantTarget { extension ConstraintConstantTarget { - internal func layoutConstantForLayoutAttribute(_ layoutAttribute: NSLayoutAttribute) -> CGFloat { + internal func constraintConstantTargetValueFor(layoutAttribute: NSLayoutAttribute) -> CGFloat { + if let value = self as? CGFloat { + return value + } + if let value = self as? Float { return CGFloat(value) } @@ -59,10 +63,6 @@ extension ConstraintConstantTarget { return CGFloat(value) } - if let value = self as? CGFloat { - return value - } - if let value = self as? CGSize { if layoutAttribute == .width { return value.width @@ -73,7 +73,6 @@ extension ConstraintConstantTarget { } } - if let value = self as? CGPoint { #if os(iOS) || os(tvOS) switch layoutAttribute { diff --git a/Source/ConstraintInsetTarget.swift b/Source/ConstraintInsetTarget.swift index df528e2..7ca58a9 100644 --- a/Source/ConstraintInsetTarget.swift +++ b/Source/ConstraintInsetTarget.swift @@ -48,3 +48,29 @@ extension CGFloat: ConstraintInsetTarget { extension ConstraintInsets: ConstraintInsetTarget { } + +extension ConstraintInsetTarget { + + internal var constraintInsetTargetValue: ConstraintInsets { + let insets: ConstraintInsets + + if let amount = self as? ConstraintInsets { + insets = amount + } else if let amount = self as? Float { + insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) + } else if let amount = self as? Double { + insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) + } else if let amount = self as? CGFloat { + insets = ConstraintInsets(top: amount, left: amount, bottom: amount, right: amount) + } else if let amount = self as? Int { + insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) + } else if let amount = self as? UInt { + insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) + } else { + insets = ConstraintInsets(top: 0, left: 0, bottom: 0, right: 0) + } + + return ConstraintInsets(top: insets.top, left: insets.left, bottom: -insets.bottom, right: -insets.right) + } + +} diff --git a/Source/ConstraintMakerEditable.swift b/Source/ConstraintMakerEditable.swift index 8c125e5..fb88c41 100644 --- a/Source/ConstraintMakerEditable.swift +++ b/Source/ConstraintMakerEditable.swift @@ -43,32 +43,13 @@ public class ConstraintMakerEditable: ConstraintMakerPriortizable { @discardableResult public func offset(_ amount: ConstraintOffsetTarget) -> ConstraintMakerEditable { - self.description.constant = amount + self.description.constant = amount.constraintOffsetTargetValue return self } @discardableResult public func inset(_ amount: ConstraintInsetTarget) -> ConstraintMakerEditable { - let insets: ConstraintInsets - - if let amount = amount as? ConstraintInsets { - insets = amount - } else if let amount = amount as? Float { - insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) - } else if let amount = amount as? Double { - insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) - } else if let amount = amount as? CGFloat { - insets = ConstraintInsets(top: amount, left: amount, bottom: amount, right: amount) - } else if let amount = amount as? Int { - insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) - } else if let amount = amount as? UInt { - insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) - } else { - insets = ConstraintInsets(top: 0, left: 0, bottom: 0, right: 0) - } - - self.description.constant = ConstraintInsets(top: insets.top, left: insets.left, bottom: -insets.bottom, right: -insets.right) - + self.description.constant = amount.constraintInsetTargetValue return self } diff --git a/Source/ConstraintOffsetTarget.swift b/Source/ConstraintOffsetTarget.swift index 9ea140d..bd9e0a1 100644 --- a/Source/ConstraintOffsetTarget.swift +++ b/Source/ConstraintOffsetTarget.swift @@ -45,3 +45,25 @@ extension Double: ConstraintOffsetTarget { extension CGFloat: ConstraintOffsetTarget { } + +extension ConstraintOffsetTarget { + + internal var constraintOffsetTargetValue: CGFloat { + let offset: CGFloat + if let amount = self as? Float { + offset = CGFloat(amount) + } else if let amount = self as? Double { + offset = CGFloat(amount) + } else if let amount = self as? CGFloat { + offset = CGFloat(amount) + } else if let amount = self as? Int { + offset = CGFloat(amount) + } else if let amount = self as? UInt { + offset = CGFloat(amount) + } else { + offset = 0.0 + } + return offset + } + +} From f5511c3bacfa5061514e775d0280b99de900b6c0 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Thu, 4 Aug 2016 10:57:23 +1200 Subject: [PATCH 21/58] Add in existing update functions and deprecate them --- Source/Constraint.swift | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index eb6387a..310c8e2 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -104,6 +104,27 @@ public class Constraint { return self } + @available(*, deprecated:0.40.0, message:"Use update(offset: ConstraintOffsetTarget) instead.") + public func updateOffset(amount: ConstraintOffsetTarget) -> Void { self.update(offset: amount) } + + @available(*, deprecated:0.40.0, message:"Use update(inset: ConstraintInsetTarget) instead.") + public func updateInsets(amount: ConstraintInsetTarget) -> Void { self.update(inset: amount) } + + @available(*, deprecated:0.40.0, message:"Use update(priority: ConstraintPriorityTarget) instead.") + public func updatePriority(amount: ConstraintPriorityTarget) -> Void { self.update(priority: amount) } + + @available(*, obsoleted:0.40.0, message:"Use update(priority: ConstraintPriorityTarget) instead.") + public func updatePriorityRequired() -> Void {} + + @available(*, obsoleted:0.40.0, message:"Use update(priority: ConstraintPriorityTarget) instead.") + public func updatePriorityHigh() -> Void { fatalError("Must be implemented by Concrete subclass.") } + + @available(*, obsoleted:0.40.0, message:"Use update(priority: ConstraintPriorityTarget) instead.") + public func updatePriorityMedium() -> Void { fatalError("Must be implemented by Concrete subclass.") } + + @available(*, obsoleted:0.40.0, message:"Use update(priority: ConstraintPriorityTarget) instead.") + public func updatePriorityLow() -> Void { fatalError("Must be implemented by Concrete subclass.") } + // MARK: Internal internal func updateConstantAndPriorityIfNeeded() { From 17a01931dba4cfd3983faf3dfc7071b81c414ff9 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Thu, 4 Aug 2016 10:57:30 +1200 Subject: [PATCH 22/58] Deprecate priority helpers --- Source/ConstraintMakerPriortizable.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/ConstraintMakerPriortizable.swift b/Source/ConstraintMakerPriortizable.swift index 9616a38..c5fe11a 100644 --- a/Source/ConstraintMakerPriortizable.swift +++ b/Source/ConstraintMakerPriortizable.swift @@ -36,16 +36,19 @@ public class ConstraintMakerPriortizable: ConstraintMakerFinalizable { return self } + @available(*, deprecated:0.40.0, message:"Use priority(_ amount: ConstraintPriorityTarget) instead.") @discardableResult public func priorityRequired() -> ConstraintMakerFinalizable { return self.priority(1000) } + @available(*, deprecated:0.40.0, message:"Use priority(_ amount: ConstraintPriorityTarget) instead.") @discardableResult public func priorityHigh() -> ConstraintMakerFinalizable { return self.priority(750) } + @available(*, deprecated:0.40.0, message:"Use priority(_ amount: ConstraintPriorityTarget) instead.") @discardableResult public func priorityMedium() -> ConstraintMakerFinalizable { #if os(iOS) || os(tvOS) @@ -55,6 +58,7 @@ public class ConstraintMakerPriortizable: ConstraintMakerFinalizable { #endif } + @available(*, deprecated:0.40.0, message:"Use priority(_ amount: ConstraintPriorityTarget) instead.") @discardableResult public func priorityLow() -> ConstraintMakerFinalizable { return self.priority(250) From 9d0232ca0879dda2cbfe7385ab4a26254de0d276 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 6 Aug 2016 22:38:02 +1200 Subject: [PATCH 23/58] API updates, migrate away from iOS 7.0 support --- SnapKit.xcodeproj/project.pbxproj | 7 +- Source/Constraint.swift | 318 +++++------------- Source/ConstraintAttributes.swift | 107 +++--- Source/ConstraintDescription.swift | 2 + Source/ConstraintMaker.swift | 79 +++-- Source/ConstraintMakerExtendable.swift | 54 +-- Source/ConstraintMakerFinalizable.swift | 6 + Source/ConstraintMakerRelatable.swift | 6 +- Source/ConstraintView+Extensions.swift | 65 ++-- .../ConstraintViewController+Extensions.swift | 8 +- Source/ConstraintViewControllerDSL.swift | 16 +- Source/ConstraintViewDSL.swift | 77 ++--- Source/LayoutConstraint.swift | 12 +- Tests/Tests.swift | 285 +++++++++++++++- 14 files changed, 608 insertions(+), 434 deletions(-) diff --git a/SnapKit.xcodeproj/project.pbxproj b/SnapKit.xcodeproj/project.pbxproj index 4cbdd63..31ba47f 100644 --- a/SnapKit.xcodeproj/project.pbxproj +++ b/SnapKit.xcodeproj/project.pbxproj @@ -507,6 +507,7 @@ EEBCC9E119CC627D0083B827 = { CreatedOnToolsVersion = 6.0; LastSwiftMigration = 0800; + ProvisioningStyle = Automatic; }; EECDB3791AC0C9D4006BBC11 = { CreatedOnToolsVersion = 6.2; @@ -945,7 +946,8 @@ EEBCC9EC19CC627E0083B827 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; @@ -957,7 +959,8 @@ EEBCC9ED19CC627E0083B827 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 310c8e2..b1d4c03 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -27,10 +27,10 @@ import AppKit #endif - public class Constraint { internal let sourceLocation: (String, UInt) + internal let label: String? private let from: ConstraintItem private let to: ConstraintItem @@ -46,7 +46,7 @@ public class Constraint { self.updateConstantAndPriorityIfNeeded() } } - private var installInfo: ConstraintInstallInfo? = nil + private let layoutConstraints: NSHashTable // MARK: Initialization @@ -54,6 +54,7 @@ public class Constraint { to: ConstraintItem, relation: ConstraintRelation, sourceLocation: (String, UInt), + label: String?, multiplier: ConstraintMultiplierTarget, constant: ConstraintConstantTarget, priority: ConstraintPriorityTarget) { @@ -61,27 +62,67 @@ public class Constraint { self.to = to self.relation = relation self.sourceLocation = sourceLocation + self.label = label self.multiplier = multiplier self.constant = constant self.priority = priority + self.layoutConstraints = NSHashTable.weakObjects() + + // get attributes + let layoutFromAttributes = self.from.attributes.layoutAttributes + let layoutToAttributes = self.to.attributes.layoutAttributes + + // get layout from + let layoutFrom: ConstraintView = self.from.view! + + // get relation + let layoutRelation = self.relation.layoutRelation + + for layoutFromAttribute in layoutFromAttributes { + // get layout to attribute + let layoutToAttribute = (layoutToAttributes.count > 0) ? layoutToAttributes[0] : layoutFromAttribute + + // get layout constant + let layoutConstant: CGFloat = self.constant.constraintConstantTargetValueFor(layoutAttribute: layoutToAttribute) + + // get layout to + #if os(iOS) || os(tvOS) + let layoutTo: AnyObject? = self.to.view ?? self.to.layoutSupport + #else + let layoutTo: AnyObject? = self.to.view + #endif + + // create layout constraint + let layoutConstraint = LayoutConstraint( + item: layoutFrom, + attribute: layoutFromAttribute, + relatedBy: layoutRelation, + toItem: layoutTo, + attribute: layoutToAttribute, + multiplier: self.multiplier.constraintMultiplierTargetValue, + constant: layoutConstant + ) + + // set label + layoutConstraint.label = self.label + + // set priority + layoutConstraint.priority = self.priority.constraintPriorityTargetValue + + // set constraint + layoutConstraint.constraint = self + + // append + self.layoutConstraints.add(layoutConstraint) + } } // MARK: Public - public func install() -> [NSLayoutConstraint] { - return self.installIfNeeded(updateExisting: false) - } - - public func uninstall() { - self.uninstallIfNeeded() - } - - @available(iOS 8.0, OSX 10.10, *) public func activate() { self.activateIfNeeded() } - @available(iOS 8.0, OSX 10.10, *) public func deactivate() { self.deactivateIfNeeded() } @@ -128,248 +169,55 @@ public class Constraint { // MARK: Internal internal func updateConstantAndPriorityIfNeeded() { - guard let installInfo = self.installInfo else { - return - } - for layoutConstraint in installInfo.layoutConstraints.allObjects as! [LayoutConstraint] { + for layoutConstraint in self.layoutConstraints.allObjects { let attribute = (layoutConstraint.secondAttribute == .notAnAttribute) ? layoutConstraint.firstAttribute : layoutConstraint.secondAttribute layoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: attribute) layoutConstraint.priority = self.priority.constraintPriorityTargetValue } } - internal func installIfNeeded(updateExisting: Bool = false) -> [NSLayoutConstraint] { - let installOnView: ConstraintView? + internal func activateIfNeeded(updatingExisting: Bool = false) { + let view = self.from.view! + let layoutConstraints = self.layoutConstraints.allObjects + let existingLayoutConstraints = view.snp.layoutConstraints - if let view = self.to.view { - guard let closestSuperview = closestCommonSuperviewFromView(self.from.view, toView: view) else { - fatalError("Cannot Install Constraint. No common superview. (\(self.sourceLocation.0), \(self.sourceLocation.1))") + if updatingExisting && existingLayoutConstraints.count > 0 { + + for layoutConstraint in layoutConstraints { + let existingLayoutConstraint = existingLayoutConstraints.first { $0 == layoutConstraint } + guard let updateLayoutConstraint = existingLayoutConstraint else { + fatalError("Updated constraint could not find existing matching constraint to update: \(layoutConstraint)") + } + + let updateLayoutAttribute = (updateLayoutConstraint.secondAttribute == .notAnAttribute) ? updateLayoutConstraint.firstAttribute : updateLayoutConstraint.secondAttribute + updateLayoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: updateLayoutAttribute) } - installOnView = closestSuperview - } else if self.from.attributes.isSubset(of: ConstraintAttributes.Width + ConstraintAttributes.Height) { - installOnView = self.from.view + } else { - guard let superview = self.from.view?.superview else { - fatalError("Cannot Install Constraint. No superview. (\(self.sourceLocation.0), \(self.sourceLocation.1))") - } - installOnView = superview + NSLayoutConstraint.activate(layoutConstraints) + view.snp.add(layoutConstraints: layoutConstraints) } - guard self.installInfo?.view == nil || - self.installInfo?.view == installOnView else { - fatalError("Cannot Install Constraint. Already installed on different view. (\(self.sourceLocation.0), \(self.sourceLocation.1))") - } - - // setup array to store new layout constraints - var newLayoutConstraints = [LayoutConstraint]() - - // get attributes - let layoutFromAttributes = self.from.attributes.layoutAttributes - let layoutToAttributes = self.to.attributes.layoutAttributes - - // get layout from - let layoutFrom: ConstraintView = self.from.view! - - // get relation - let layoutRelation = self.relation.layoutRelation - - for layoutFromAttribute in layoutFromAttributes { - // get layout to attribute - let layoutToAttribute = (layoutToAttributes.count > 0) ? layoutToAttributes[0] : layoutFromAttribute - - // get layout constant - 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 - if layoutTo == nil && layoutToAttribute != .width && layoutToAttribute != .height { - layoutTo = installOnView - } - - // create layout constraint - let layoutConstraint = LayoutConstraint( - item: layoutFrom, - attribute: layoutFromAttribute, - relatedBy: layoutRelation, - toItem: layoutTo, - attribute: layoutToAttribute, - multiplier: self.multiplier.constraintMultiplierTargetValue, - constant: layoutConstant - ) - - // set priority - layoutConstraint.priority = self.priority.constraintPriorityTargetValue - - // set constraint - layoutConstraint.constraint = self - - // append - newLayoutConstraints.append(layoutConstraint) - } - - // updating logic - if updateExisting { - - // get existing constraints for this view - let existingLayoutConstraints = layoutFrom.snp.installedLayoutConstraints.reversed() - - // array that will contain only new layout constraints to keep - var newLayoutConstraintsToKeep = [LayoutConstraint]() - - // begin looping - for layoutConstraint in newLayoutConstraints { - // layout constraint that should be updated - var updateLayoutConstraint: LayoutConstraint? = nil - - // loop through existing and check for match - for existingLayoutConstraint in existingLayoutConstraints { - if existingLayoutConstraint == layoutConstraint { - updateLayoutConstraint = existingLayoutConstraint - break - } - } - - // if we have existing one lets just update the constant - if updateLayoutConstraint != nil { - updateLayoutConstraint!.constant = layoutConstraint.constant - } - // otherwise add this layout constraint to new keep list - else { - newLayoutConstraintsToKeep.append(layoutConstraint) - } - } - - // set constraints to only new ones - newLayoutConstraints = newLayoutConstraintsToKeep - } - - // add constraints - #if SNAPKIT_DEPLOYMENT_LEGACY && (os(iOS) || os(tvOS)) - if #available(iOS 8.0, *) { - NSLayoutConstraint.activate(newLayoutConstraints) - } else { - installOnView?.addConstraints(newLayoutConstraints) - } - #else - NSLayoutConstraint.activate(newLayoutConstraints) - #endif - - // set install info - self.installInfo = ConstraintInstallInfo(view: installOnView, layoutConstraints: NSHashTable.weakObjects()) - - // store which layout constraints are installed for this constraint - for layoutConstraint in newLayoutConstraints { - self.installInfo!.layoutConstraints.add(layoutConstraint) - } - - // store the layout constraints against the layout from view - layoutFrom.snp.appendInstalledLayoutConstraints(newLayoutConstraints) - - return newLayoutConstraints - } - - internal func uninstallIfNeeded() { - defer { - self.installInfo = nil - } - - guard let installedLayoutConstraints = self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint], - installedLayoutConstraints.count > 0 else { - return - } - - #if SNAPKIT_DEPLOYMENT_LEGACY && !os(OSX) - if #available(iOS 8.0, *) { - NSLayoutConstraint.deactivate(installedLayoutConstraints) - } else if let installedOnView = installInfo?.view { - installedOnView.removeConstraints(installedLayoutConstraints) - } - #else - NSLayoutConstraint.deactivate(installedLayoutConstraints) - #endif - - // remove the constraints from the from item view - self.from.view?.snp.removeInstalledLayoutConstraints(installedLayoutConstraints) - } - - internal func activateIfNeeded() { - guard self.installInfo != nil else { - _ = self.installIfNeeded() - return - } - #if SNAPKIT_DEPLOYMENT_LEGACY - guard #available(iOS 8.0, OSX 10.10, *) else { - _ = self.installIfNeeded() - return - } - #endif - - guard let layoutConstraints = self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint], - layoutConstraints.count > 0 else { - return - } - - NSLayoutConstraint.activate(layoutConstraints) + print(view, layoutConstraints.count, existingLayoutConstraints.count) } internal func deactivateIfNeeded() { - #if SNAPKIT_DEPLOYMENT_LEGACY - guard #available(iOS 8.0, OSX 10.10, *) else { - return - } - #endif - - guard let layoutConstraints = self.installInfo?.layoutConstraints.allObjects as? [LayoutConstraint], - layoutConstraints.count > 0 else { - return - } - + let view = self.from.view! + let layoutConstraints = self.layoutConstraints.allObjects NSLayoutConstraint.deactivate(layoutConstraints) + view.snp.remove(layoutConstraints: layoutConstraints) + } +} + +extension Constraint: Hashable { + + public var hashValue: Int { + return self.layoutConstraints.hashValue } } -private final class ConstraintInstallInfo { - - private weak var view: ConstraintView? = nil - private let layoutConstraints: NSHashTable - - private init(view: ConstraintView?, layoutConstraints: NSHashTable) { - self.view = view - self.layoutConstraints = layoutConstraints - } - -} - -private func closestCommonSuperviewFromView(_ fromView: ConstraintView?, toView: ConstraintView?) -> ConstraintView? { - var views = Set() - var fromView = fromView - var toView = toView - repeat { - if let view = toView { - if views.contains(view) { - return view - } - views.insert(view) - toView = view.superview - } - if let view = fromView { - if views.contains(view) { - return view - } - views.insert(view) - fromView = view.superview - } - } while (fromView != nil || toView != nil) - - return nil -} - -private func ==(lhs: Constraint, rhs: Constraint) -> Bool { +public func ==(lhs: Constraint, rhs: Constraint) -> Bool { return (lhs.from == rhs.from && lhs.to == rhs.to && lhs.relation == rhs.relation && diff --git a/Source/ConstraintAttributes.swift b/Source/ConstraintAttributes.swift index 3c4cf68..7236d24 100644 --- a/Source/ConstraintAttributes.swift +++ b/Source/ConstraintAttributes.swift @@ -51,117 +51,120 @@ internal struct ConstraintAttributes: OptionSet { // normal - internal static var None: ConstraintAttributes { return self.init(0) } - internal static var Left: ConstraintAttributes { return self.init(1) } - internal static var Top: ConstraintAttributes { return self.init(2) } - internal static var Right: ConstraintAttributes { return self.init(4) } - internal static var Bottom: ConstraintAttributes { return self.init(8) } - internal static var Leading: ConstraintAttributes { return self.init(16) } - internal static var Trailing: ConstraintAttributes { return self.init(32) } - internal static var Width: ConstraintAttributes { return self.init(64) } - internal static var Height: ConstraintAttributes { return self.init(128) } - internal static var CenterX: ConstraintAttributes { return self.init(256) } - internal static var CenterY: ConstraintAttributes { return self.init(512) } - internal static var Baseline: ConstraintAttributes { return self.init(1024) } + internal static var none: ConstraintAttributes { return self.init(0) } + internal static var left: ConstraintAttributes { return self.init(1) } + internal static var top: ConstraintAttributes { return self.init(2) } + internal static var right: ConstraintAttributes { return self.init(4) } + internal static var bottom: ConstraintAttributes { return self.init(8) } + internal static var leading: ConstraintAttributes { return self.init(16) } + internal static var trailing: ConstraintAttributes { return self.init(32) } + internal static var width: ConstraintAttributes { return self.init(64) } + internal static var height: ConstraintAttributes { return self.init(128) } + internal static var centerX: ConstraintAttributes { return self.init(256) } + internal static var centerY: ConstraintAttributes { return self.init(512) } + internal static var lastBaseline: ConstraintAttributes { return self.init(1024) } + + @available(iOS 8.0, OSX 10.11, *) + internal static var firstBaseline: ConstraintAttributes { return self.init(2048) } @available(iOS 8.0, *) - internal static var FirstBaseline: ConstraintAttributes { return self.init(2048) } + internal static var leftMargin: ConstraintAttributes { return self.init(4096) } + @available(iOS 8.0, *) - internal static var LeftMargin: ConstraintAttributes { return self.init(4096) } + internal static var rightMargin: ConstraintAttributes { return self.init(8192) } + @available(iOS 8.0, *) - internal static var RightMargin: ConstraintAttributes { return self.init(8192) } + internal static var topMargin: ConstraintAttributes { return self.init(16384) } + @available(iOS 8.0, *) - internal static var TopMargin: ConstraintAttributes { return self.init(16384) } + internal static var bottomMargin: ConstraintAttributes { return self.init(32768) } + @available(iOS 8.0, *) - internal static var BottomMargin: ConstraintAttributes { return self.init(32768) } + internal static var leadingMargin: ConstraintAttributes { return self.init(65536) } + @available(iOS 8.0, *) - internal static var LeadingMargin: ConstraintAttributes { return self.init(65536) } + internal static var trailingMargin: ConstraintAttributes { return self.init(131072) } + @available(iOS 8.0, *) - internal static var TrailingMargin: ConstraintAttributes { return self.init(131072) } + internal static var centerXWithinMargins: ConstraintAttributes { return self.init(262144) } + @available(iOS 8.0, *) - internal static var CenterXWithinMargins: ConstraintAttributes { return self.init(262144) } - @available(iOS 8.0, *) - internal static var CenterYWithinMargins: ConstraintAttributes { return self.init(524288) } + internal static var centerYWithinMargins: ConstraintAttributes { return self.init(524288) } // aggregates - internal static var Edges: ConstraintAttributes { return self.init(15) } - internal static var Size: ConstraintAttributes { return self.init(192) } - internal static var Center: ConstraintAttributes { return self.init(768) } + internal static var edges: ConstraintAttributes { return self.init(15) } + internal static var size: ConstraintAttributes { return self.init(192) } + internal static var center: ConstraintAttributes { return self.init(768) } @available(iOS 8.0, *) - internal static var Margins: ConstraintAttributes { return self.init(61440) } + internal static var margins: ConstraintAttributes { return self.init(61440) } @available(iOS 8.0, *) - internal static var CenterWithinMargins: ConstraintAttributes { return self.init(786432) } + internal static var centerWithinMargins: ConstraintAttributes { return self.init(786432) } internal var layoutAttributes:[NSLayoutAttribute] { var attrs = [NSLayoutAttribute]() - if (self.contains(ConstraintAttributes.Left)) { + if (self.contains(ConstraintAttributes.left)) { attrs.append(.left) } - if (self.contains(ConstraintAttributes.Top)) { + if (self.contains(ConstraintAttributes.top)) { attrs.append(.top) } - if (self.contains(ConstraintAttributes.Right)) { + if (self.contains(ConstraintAttributes.right)) { attrs.append(.right) } - if (self.contains(ConstraintAttributes.Bottom)) { + if (self.contains(ConstraintAttributes.bottom)) { attrs.append(.bottom) } - if (self.contains(ConstraintAttributes.Leading)) { + if (self.contains(ConstraintAttributes.leading)) { attrs.append(.leading) } - if (self.contains(ConstraintAttributes.Trailing)) { + if (self.contains(ConstraintAttributes.trailing)) { attrs.append(.trailing) } - if (self.contains(ConstraintAttributes.Width)) { + if (self.contains(ConstraintAttributes.width)) { attrs.append(.width) } - if (self.contains(ConstraintAttributes.Height)) { + if (self.contains(ConstraintAttributes.height)) { attrs.append(.height) } - if (self.contains(ConstraintAttributes.CenterX)) { + if (self.contains(ConstraintAttributes.centerX)) { attrs.append(.centerX) } - if (self.contains(ConstraintAttributes.CenterY)) { + if (self.contains(ConstraintAttributes.centerY)) { attrs.append(.centerY) } - if (self.contains(ConstraintAttributes.Baseline)) { + if (self.contains(ConstraintAttributes.lastBaseline)) { attrs.append(.lastBaseline) } #if os(iOS) || os(tvOS) - #if SNAPKIT_DEPLOYMENT_LEGACY - guard #available(iOS 8.0, *) else { - return attrs - } - #endif - if (self.contains(ConstraintAttributes.FirstBaseline)) { + if (self.contains(ConstraintAttributes.firstBaseline)) { attrs.append(.firstBaseline) } - if (self.contains(ConstraintAttributes.LeftMargin)) { + if (self.contains(ConstraintAttributes.leftMargin)) { attrs.append(.leftMargin) } - if (self.contains(ConstraintAttributes.RightMargin)) { + if (self.contains(ConstraintAttributes.rightMargin)) { attrs.append(.rightMargin) } - if (self.contains(ConstraintAttributes.TopMargin)) { + if (self.contains(ConstraintAttributes.topMargin)) { attrs.append(.topMargin) } - if (self.contains(ConstraintAttributes.BottomMargin)) { + if (self.contains(ConstraintAttributes.bottomMargin)) { attrs.append(.bottomMargin) } - if (self.contains(ConstraintAttributes.LeadingMargin)) { + if (self.contains(ConstraintAttributes.leadingMargin)) { attrs.append(.leadingMargin) } - if (self.contains(ConstraintAttributes.TrailingMargin)) { + if (self.contains(ConstraintAttributes.trailingMargin)) { attrs.append(.trailingMargin) } - if (self.contains(ConstraintAttributes.CenterXWithinMargins)) { + if (self.contains(ConstraintAttributes.centerXWithinMargins)) { attrs.append(.centerXWithinMargins) } - if (self.contains(ConstraintAttributes.CenterYWithinMargins)) { + if (self.contains(ConstraintAttributes.centerYWithinMargins)) { attrs.append(.centerYWithinMargins) } #endif diff --git a/Source/ConstraintDescription.swift b/Source/ConstraintDescription.swift index d0189ae..6eae505 100644 --- a/Source/ConstraintDescription.swift +++ b/Source/ConstraintDescription.swift @@ -34,6 +34,7 @@ public class ConstraintDescription { internal var attributes: ConstraintAttributes internal var relation: ConstraintRelation? = nil internal var sourceLocation: (String, UInt)? = nil + internal var label: String? = nil internal var related: ConstraintItem? = nil internal var multiplier: ConstraintMultiplierTarget = 1.0 internal var constant: ConstraintConstantTarget = 0.0 @@ -51,6 +52,7 @@ public class ConstraintDescription { to: related, relation: relation, sourceLocation: sourceLocation, + label: self.label, multiplier: self.multiplier, constant: self.constant, priority: self.priority diff --git a/Source/ConstraintMaker.swift b/Source/ConstraintMaker.swift index 746b44b..94f1556 100644 --- a/Source/ConstraintMaker.swift +++ b/Source/ConstraintMaker.swift @@ -30,95 +30,109 @@ public class ConstraintMaker { public var left: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.Left) + return self.makeExtendableWithAttributes(.left) } + public var top: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.Top) + return self.makeExtendableWithAttributes(.top) } + public var bottom: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.Bottom) + return self.makeExtendableWithAttributes(.bottom) } + public var right: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.Right) + return self.makeExtendableWithAttributes(.right) } + public var leading: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.Leading) + return self.makeExtendableWithAttributes(.leading) } + public var trailing: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.Trailing) + return self.makeExtendableWithAttributes(.trailing) } + public var width: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.Width) + return self.makeExtendableWithAttributes(.width) } + public var height: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.Height) + return self.makeExtendableWithAttributes(.height) } public var centerX: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.CenterX) - } - public var centerY: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.CenterY) - } - public var baseline: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.Baseline) + return self.makeExtendableWithAttributes(.centerX) } - @available(iOS 8.0, *) + public var centerY: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(.centerY) + } + + @available(*, deprecated:0.40.0, message:"Use lastBaseline instead") + public var baseline: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(.lastBaseline) + } + + public var lastBaseline: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(.lastBaseline) + } + + @available(iOS 8.0, OSX 10.11, *) public var firstBaseline: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.FirstBaseline) + return self.makeExtendableWithAttributes(.firstBaseline) } @available(iOS 8.0, *) public var leftMargin: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.LeftMargin) + return self.makeExtendableWithAttributes(.leftMargin) } @available(iOS 8.0, *) public var rightMargin: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.RightMargin) + return self.makeExtendableWithAttributes(.rightMargin) } @available(iOS 8.0, *) public var bottomMargin: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.BottomMargin) + return self.makeExtendableWithAttributes(.bottomMargin) } @available(iOS 8.0, *) public var leadingMargin: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.LeadingMargin) + return self.makeExtendableWithAttributes(.leadingMargin) } @available(iOS 8.0, *) public var trailingMargin: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.TrailingMargin) + return self.makeExtendableWithAttributes(.trailingMargin) } @available(iOS 8.0, *) public var centerXWithinMargins: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.CenterXWithinMargins) + return self.makeExtendableWithAttributes(.centerXWithinMargins) } @available(iOS 8.0, *) public var centerYWithinMargins: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.CenterYWithinMargins) + return self.makeExtendableWithAttributes(.centerYWithinMargins) } public var edges: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.Edges) + return self.makeExtendableWithAttributes(.edges) } public var size: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.Size) + return self.makeExtendableWithAttributes(.size) } @available(iOS 8.0, *) public var margins: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.Margins) + return self.makeExtendableWithAttributes(.margins) } @available(iOS 8.0, *) public var centerWithinMargins: ConstraintMakerExtendable { - return self.makeExtendableWithAttributes(ConstraintAttributes.CenterWithinMargins) + return self.makeExtendableWithAttributes(.centerWithinMargins) } private let view: ConstraintView @@ -153,7 +167,7 @@ public class ConstraintMaker { .filter { $0 != nil } .map { $0! } for constraint in constraints { - let _ = constraint.installIfNeeded() + constraint.activateIfNeeded(updatingExisting: false) } } @@ -170,13 +184,14 @@ public class ConstraintMaker { .filter { $0 != nil } .map { $0! } for constraint in constraints { - let _ = constraint.installIfNeeded(updateExisting: true) + constraint.activateIfNeeded(updatingExisting: true) } } internal static func removeConstraints(view: ConstraintView) { - for layoutConstraint in view.snp.installedLayoutConstraints { - layoutConstraint.constraint?.uninstall() + let constraints = view.snp.layoutConstraints.map { $0.constraint! } + for constraint in constraints { + constraint.deactivateIfNeeded() } } diff --git a/Source/ConstraintMakerExtendable.swift b/Source/ConstraintMakerExtendable.swift index 220bf16..2a57da9 100644 --- a/Source/ConstraintMakerExtendable.swift +++ b/Source/ConstraintMakerExtendable.swift @@ -31,126 +31,132 @@ public class ConstraintMakerExtendable: ConstraintMakerRelatable { public var left: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.Left + self.description.attributes += .left return self } public var top: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.Top + self.description.attributes += .top return self } public var bottom: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.Bottom + self.description.attributes += .bottom return self } public var right: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.Right + self.description.attributes += .right return self } public var leading: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.Leading + self.description.attributes += .leading return self } public var trailing: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.Trailing + self.description.attributes += .trailing return self } public var width: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.Width + self.description.attributes += .width return self } public var height: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.Height + self.description.attributes += .height return self } public var centerX: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.CenterX + self.description.attributes += .centerX return self } public var centerY: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.CenterY + self.description.attributes += .centerY return self } + @available(*, deprecated:0.40.0, message:"Use lastBaseline instead") public var baseline: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.Baseline + self.description.attributes += .lastBaseline return self } - @available(iOS 8.0, *) + public var lastBaseline: ConstraintMakerExtendable { + self.description.attributes += .lastBaseline + return self + } + + @available(iOS 8.0, OSX 10.11, *) public var firstBaseline: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.FirstBaseline + self.description.attributes += .firstBaseline return self } @available(iOS 8.0, *) public var leftMargin: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.LeftMargin + self.description.attributes += .leftMargin return self } @available(iOS 8.0, *) public var rightMargin: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.RightMargin + self.description.attributes += .rightMargin return self } @available(iOS 8.0, *) public var bottomMargin: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.BottomMargin + self.description.attributes += .bottomMargin return self } @available(iOS 8.0, *) public var leadingMargin: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.LeadingMargin + self.description.attributes += .leadingMargin return self } @available(iOS 8.0, *) public var trailingMargin: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.TrailingMargin + self.description.attributes += .trailingMargin return self } @available(iOS 8.0, *) public var centerXWithinMargins: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.CenterXWithinMargins + self.description.attributes += .centerXWithinMargins return self } @available(iOS 8.0, *) public var centerYWithinMargins: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.CenterYWithinMargins + self.description.attributes += .centerYWithinMargins return self } public var edges: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.Edges + self.description.attributes += .edges return self } public var size: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.Size + self.description.attributes += .size return self } @available(iOS 8.0, *) public var margins: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.Margins + self.description.attributes += .margins return self } @available(iOS 8.0, *) public var centerWithinMargins: ConstraintMakerExtendable { - self.description.attributes += ConstraintAttributes.CenterWithinMargins + self.description.attributes += .centerWithinMargins return self } diff --git a/Source/ConstraintMakerFinalizable.swift b/Source/ConstraintMakerFinalizable.swift index 480f9c8..4e1379e 100644 --- a/Source/ConstraintMakerFinalizable.swift +++ b/Source/ConstraintMakerFinalizable.swift @@ -36,6 +36,12 @@ public class ConstraintMakerFinalizable { self.description = description } + @discardableResult + public func labeled(_ label: String) -> ConstraintMakerFinalizable { + self.description.label = label + return self + } + public var constraint: Constraint { return self.description.constraint! } diff --git a/Source/ConstraintMakerRelatable.swift b/Source/ConstraintMakerRelatable.swift index bab6369..c4141be 100644 --- a/Source/ConstraintMakerRelatable.swift +++ b/Source/ConstraintMakerRelatable.swift @@ -41,7 +41,7 @@ public class ConstraintMakerRelatable { let constant: ConstraintConstantTarget if let other = other as? ConstraintItem { - guard other.attributes == ConstraintAttributes.None || + guard other.attributes == ConstraintAttributes.none || other.attributes.layoutAttributes.count <= 1 || other.attributes.layoutAttributes == self.description.attributes.layoutAttributes else { fatalError("Cannot constraint to multiple non identical attributes. (\(file), \(line))"); @@ -50,10 +50,10 @@ public class ConstraintMakerRelatable { related = other constant = 0.0 } else if let other = other as? ConstraintView { - related = ConstraintItem(target: other, attributes: ConstraintAttributes.None) + related = ConstraintItem(target: other, attributes: ConstraintAttributes.none) constant = 0.0 } else if let other = other as? ConstraintConstantTarget { - related = ConstraintItem(target: nil, attributes: ConstraintAttributes.None) + related = ConstraintItem(target: nil, attributes: ConstraintAttributes.none) constant = other } else { fatalError("Invalid constraint. (\(file), \(line))") diff --git a/Source/ConstraintView+Extensions.swift b/Source/ConstraintView+Extensions.swift index 0e89a32..5406cdf 100644 --- a/Source/ConstraintView+Extensions.swift +++ b/Source/ConstraintView+Extensions.swift @@ -30,117 +30,116 @@ public extension ConstraintView { - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_left: ConstraintItem { return self.snp.left } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_top: ConstraintItem { return self.snp.top } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_right: ConstraintItem { return self.snp.right } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_bottom: ConstraintItem { return self.snp.bottom } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_leading: ConstraintItem { return self.snp.leading } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_trailing: ConstraintItem { return self.snp.trailing } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_width: ConstraintItem { return self.snp.width } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_height: ConstraintItem { return self.snp.height } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_centerX: ConstraintItem { return self.snp.centerX } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_centerY: ConstraintItem { return self.snp.centerY } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_baseline: ConstraintItem { return self.snp.baseline } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") - @available(iOS 8.0, OSX 10.11, *) + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_lastBaseline: ConstraintItem { return self.snp.lastBaseline } - @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") @available(iOS 8.0, OSX 10.11, *) public var snp_firstBaseline: ConstraintItem { return self.snp.firstBaseline } - @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") - @available(iOS 8.0, OSX 10.11, *) + @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") + @available(iOS 8.0, *) public var snp_leftMargin: ConstraintItem { return self.snp.leftMargin } - @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") @available(iOS 8.0, *) public var snp_topMargin: ConstraintItem { return self.snp.topMargin } - @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") @available(iOS 8.0, *) public var snp_rightMargin: ConstraintItem { return self.snp.rightMargin } - @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") @available(iOS 8.0, *) public var snp_bottomMargin: ConstraintItem { return self.snp.bottomMargin } - @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") @available(iOS 8.0, *) public var snp_leadingMargin: ConstraintItem { return self.snp.leadingMargin } - @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") @available(iOS 8.0, *) public var snp_trailingMargin: ConstraintItem { return self.snp.trailingMargin } - @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") @available(iOS 8.0, *) public var snp_centerXWithinMargins: ConstraintItem { return self.snp.centerXWithinMargins } - @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") @available(iOS 8.0, *) public var snp_centerYWithinMargins: ConstraintItem { return self.snp.centerYWithinMargins } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_edges: ConstraintItem { return self.snp.edges } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_size: ConstraintItem { return self.snp.size } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var snp_center: ConstraintItem { return self.snp.center } - @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") @available(iOS 8.0, *) public var snp_margins: ConstraintItem { return self.snp.margins } - @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") @available(iOS 8.0, *) public var snp_centerWithinMargins: ConstraintItem { return self.snp.centerWithinMargins } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public func snp_prepareConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) -> [Constraint] { return self.snp.prepareConstraints(closure) } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public func snp_makeConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { self.snp.makeConstraints(closure) } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public func snp_remakeConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { self.snp.remakeConstraints(closure) } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public func snp_updateConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { self.snp.updateConstraints(closure) } - @available(*, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") public func snp_removeConstraints() { self.snp.removeConstraints() } diff --git a/Source/ConstraintViewController+Extensions.swift b/Source/ConstraintViewController+Extensions.swift index c7b18fe..4324b13 100644 --- a/Source/ConstraintViewController+Extensions.swift +++ b/Source/ConstraintViewController+Extensions.swift @@ -27,22 +27,22 @@ public extension ConstraintViewController { - @available(iOS, deprecated:0.40.0, message:"Please use newer snp.* syntax.") + @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:"Please use newer snp.* syntax.") + @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:"Please use newer snp.* syntax.") + @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:"Please use newer snp.* syntax.") + @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") public var bottomLayoutGuideBottom: ConstraintItem { return self.snp.bottomLayoutGuideBottom } diff --git a/Source/ConstraintViewControllerDSL.swift b/Source/ConstraintViewControllerDSL.swift index b632c99..137b7b5 100644 --- a/Source/ConstraintViewControllerDSL.swift +++ b/Source/ConstraintViewControllerDSL.swift @@ -27,24 +27,24 @@ public struct ConstraintViewControllerDSL { - @available(iOS 7.0, *) + @available(iOS 8.0, *) public var topLayoutGuideTop: ConstraintItem { - return ConstraintItem(target: self.viewController.topLayoutGuide, attributes: ConstraintAttributes.Top) + return ConstraintItem(target: self.viewController.topLayoutGuide, attributes: ConstraintAttributes.top) } - @available(iOS 7.0, *) + @available(iOS 8.0, *) public var topLayoutGuideBottom: ConstraintItem { - return ConstraintItem(target: self.viewController.topLayoutGuide, attributes: ConstraintAttributes.Bottom) + return ConstraintItem(target: self.viewController.topLayoutGuide, attributes: ConstraintAttributes.bottom) } - @available(iOS 7.0, *) + @available(iOS 8.0, *) public var bottomLayoutGuideTop: ConstraintItem { - return ConstraintItem(target: self.viewController.bottomLayoutGuide, attributes: ConstraintAttributes.Top) + return ConstraintItem(target: self.viewController.bottomLayoutGuide, attributes: ConstraintAttributes.top) } - @available(iOS 7.0, *) + @available(iOS 8.0, *) public var bottomLayoutGuideBottom: ConstraintItem { - return ConstraintItem(target: self.viewController.bottomLayoutGuide, attributes: ConstraintAttributes.Bottom) + return ConstraintItem(target: self.viewController.bottomLayoutGuide, attributes: ConstraintAttributes.bottom) } internal let viewController: ConstraintViewController diff --git a/Source/ConstraintViewDSL.swift b/Source/ConstraintViewDSL.swift index 35a4c39..7d5f136 100644 --- a/Source/ConstraintViewDSL.swift +++ b/Source/ConstraintViewDSL.swift @@ -31,122 +31,123 @@ public struct ConstraintViewDSL { public var left: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Left) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.left) } public var top: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Top) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.top) } public var right: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Right) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.right) } public var bottom: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Bottom) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.bottom) } public var leading: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Leading) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.leading) } public var trailing: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Trailing) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.trailing) } public var width: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Width) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.width) } public var height: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Height) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.height) } public var centerX: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.CenterX) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.centerX) } public var centerY: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.CenterY) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.centerY) } - @available(*, deprecated:0.40.0, message:"Please use migrated .lastBaseline") + @available(*, deprecated:0.40.0, message:"Use .lastBaseline instead") public var baseline: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Baseline) + 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.Baseline) + 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) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.firstBaseline) } @available(iOS 8.0, *) public var leftMargin: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.LeftMargin) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.leftMargin) } @available(iOS 8.0, *) public var topMargin: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.TopMargin) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.topMargin) } @available(iOS 8.0, *) public var rightMargin: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.RightMargin) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.rightMargin) } @available(iOS 8.0, *) public var bottomMargin: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.BottomMargin) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.bottomMargin) } @available(iOS 8.0, *) public var leadingMargin: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.LeadingMargin) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.leadingMargin) } @available(iOS 8.0, *) public var trailingMargin: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.TrailingMargin) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.trailingMargin) } @available(iOS 8.0, *) public var centerXWithinMargins: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.CenterXWithinMargins) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.centerXWithinMargins) } @available(iOS 8.0, *) public var centerYWithinMargins: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.CenterYWithinMargins) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.centerYWithinMargins) } public var edges: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Edges) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.edges) } public var size: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Size) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.size) } public var center: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Center) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.center) } @available(iOS 8.0, *) public var margins: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.Margins) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.margins) } @available(iOS 8.0, *) public var centerWithinMargins: ConstraintItem { - return ConstraintItem(target: self.view, attributes: ConstraintAttributes.CenterWithinMargins) + return ConstraintItem(target: self.view, attributes: ConstraintAttributes.centerWithinMargins) } + @discardableResult public func prepareConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) -> [Constraint] { return ConstraintMaker.prepareConstraints(view: self.view, closure: closure) } @@ -216,23 +217,23 @@ public struct ConstraintViewDSL { internal init(view: ConstraintView) { self.view = view + } - internal var installedLayoutConstraints: [LayoutConstraint] { - return objc_getAssociatedObject(self.view, &installedLayoutConstraintsKey) as? [LayoutConstraint] ?? [] + internal var layoutConstraints: [LayoutConstraint] { + return objc_getAssociatedObject(self.view, &layoutConstraintsKey) as? [LayoutConstraint] ?? [] } - internal func appendInstalledLayoutConstraints(_ layoutConstraints: [LayoutConstraint]) { - var newValue = self.installedLayoutConstraints - newValue += layoutConstraints - objc_setAssociatedObject(self.view, &installedLayoutConstraintsKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + internal func add(layoutConstraints: [LayoutConstraint]) { + let merged = self.layoutConstraints + layoutConstraints + objc_setAssociatedObject(self.view, &layoutConstraintsKey, merged, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) } - internal func removeInstalledLayoutConstraints(_ layoutConstraints: [LayoutConstraint]) { - let newValue = self.installedLayoutConstraints.filter { !layoutConstraints.contains($0) } - objc_setAssociatedObject(self.view, &installedLayoutConstraintsKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + internal func remove(layoutConstraints: [LayoutConstraint]) { + let merged = self.layoutConstraints.filter { !layoutConstraints.contains($0) } + objc_setAssociatedObject(self.view, &layoutConstraintsKey, merged, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) } + } - private var labelKey: UInt8 = 0 -private var installedLayoutConstraintsKey: UInt8 = 0 +private var layoutConstraintsKey: UInt8 = 0 diff --git a/Source/LayoutConstraint.swift b/Source/LayoutConstraint.swift index 0bdf281..3dbe3ab 100644 --- a/Source/LayoutConstraint.swift +++ b/Source/LayoutConstraint.swift @@ -30,8 +30,16 @@ public class LayoutConstraint: NSLayoutConstraint { - internal var constraint: Constraint? = nil - public var label: String? = nil + public var label: String? { + get { + return self.identifier + } + set { + self.identifier = newValue + } + } + + internal var constraint: Constraint! = nil } diff --git a/Tests/Tests.swift b/Tests/Tests.swift index c5791d0..be74ad0 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -13,7 +13,7 @@ extension View { #endif import XCTest -import SnapKit +@testable import SnapKit class SnapKitTests: XCTestCase { @@ -29,4 +29,287 @@ class SnapKitTests: XCTestCase { super.tearDown() } + func testLayoutGuideConstraints() { + #if os(iOS) || os(tvOS) + let vc = UIViewController() + vc.view = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) + + vc.view.addSubview(self.container) + + self.container.snp.makeConstraints { (make) -> Void in + make.top.equalTo(vc.snp.topLayoutGuideBottom) + make.bottom.equalTo(vc.snp.bottomLayoutGuideTop) + } + + XCTAssertEqual(vc.view.snp_constraints.count, 6, "Should have 6 constraints installed") + #endif + } + + func testMakeConstraints() { + let v1 = View() + let v2 = View() + self.container.addSubview(v1) + self.container.addSubview(v2) + + v1.snp.makeConstraints { (make) -> Void in + make.top.equalTo(v2.snp.top).offset(50) + make.left.equalTo(v2.snp.top).offset(50) + return + } + + XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed") + + v2.snp.makeConstraints { (make) -> Void in + make.edges.equalTo(v1) + return + } + + XCTAssertEqual(self.container.snp_constraints.count, 6, "Should have 6 constraints installed") + + } + + func testUpdateConstraints() { + let v1 = View() + let v2 = View() + self.container.addSubview(v1) + self.container.addSubview(v2) + + print(v1) + + v1.snp.makeConstraints { (make) -> Void in + make.top.equalTo(v2.snp.top).offset(50) + make.left.equalTo(v2.snp.top).offset(50) + return + } + + XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed") + + v1.snp.updateConstraints { (make) -> Void in + make.top.equalTo(v2.snp.top).offset(15) + return + } + + XCTAssertEqual(self.container.snp_constraints.count, 2, "Should still have 2 constraints installed") + + } + + func testRemakeConstraints() { + let v1 = View() + let v2 = View() + self.container.addSubview(v1) + self.container.addSubview(v2) + + v1.snp.makeConstraints { (make) -> Void in + make.top.equalTo(v2.snp.top).offset(50) + make.left.equalTo(v2.snp.top).offset(50) + return + } + + XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed") + + v1.snp.remakeConstraints { (make) -> Void in + make.edges.equalTo(v2) + return + } + + XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints installed") + + } + + func testRemoveConstraints() { + let v1 = View() + let v2 = View() + self.container.addSubview(v1) + self.container.addSubview(v2) + + v1.snp.makeConstraints { (make) -> Void in + make.top.equalTo(v2.snp.top).offset(50) + make.left.equalTo(v2.snp.top).offset(50) + return + } + + XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed") + + v1.snp.removeConstraints() + + XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed") + + } + + func testPrepareConstraints() { + let v1 = View() + let v2 = View() + self.container.addSubview(v1) + self.container.addSubview(v2) + + let constraints = v1.snp.prepareConstraints { (make) -> Void in + make.edges.equalTo(v2) + return + } + + XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed") + + for constraint in constraints { + constraint.activate() + } + + XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints installed") + + for constraint in constraints { + constraint.deactivate() + } + + XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed") + + } + + func testReactivateConstraints() { + let v1 = View() + let v2 = View() + self.container.addSubview(v1) + self.container.addSubview(v2) + + let constraints = v1.snp.prepareConstraints { (make) -> Void in + make.edges.equalTo(v2) + return + } + + + XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed") + + for constraint in constraints { + constraint.activate() + } + + XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints installed") + + for constraint in constraints { + constraint.deactivate() + } + + XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed") + } + + func testActivateDeactivateConstraints() { + let v1 = View() + let v2 = View() + self.container.addSubview(v1) + self.container.addSubview(v2) + + var c1: Constraint? = nil + var c2: Constraint? = nil + + v1.snp.prepareConstraints { (make) -> Void in + c1 = make.top.equalTo(v2.snp.top).offset(50).constraint + c2 = make.left.equalTo(v2.snp.top).offset(50).constraint + return + } + + XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints") + + c1?.activate() + c2?.activate() + + XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints") + + c1?.deactivate() + c2?.deactivate() + + XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints") + + c1?.activate() + c2?.activate() + + XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints") + + } + + func testSizeConstraints() { + let view = View() + self.container.addSubview(view) + + view.snp.makeConstraints { (make) -> Void in + make.size.equalTo(CGSize(width: 50, height: 50)) + make.left.top.equalTo(self.container) + } + + XCTAssertEqual(view.snp_constraints.count, 2, "Should have 2 constraints") + + XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints") + + + let constraints = view.snp_constraints as! [NSLayoutConstraint] + + XCTAssertEqual(constraints[0].firstAttribute.rawValue, NSLayoutAttribute.width.rawValue, "Should be width") + XCTAssertEqual(constraints[1].firstAttribute.rawValue, NSLayoutAttribute.height.rawValue, "Should be height") + XCTAssertEqual(constraints[0].constant, 50, "Should be 50") + XCTAssertEqual(constraints[1].constant, 50, "Should be 50") + } + + func testConstraintIdentifier() { + let identifier = "Test-Identifier" + let view = View() + self.container.addSubview(view) + + view.snp.makeConstraints { (make) -> Void in + make.top.equalTo(self.container.snp.top).labeled(identifier) + } + + 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") +//// } + } From bb567ee859253f250b71e14127140de883052695 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 6 Aug 2016 22:50:51 +1200 Subject: [PATCH 24/58] Updated Changelog --- CHANGELOG.md | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d9c2b9..8ea4a65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,27 @@ CHANGELOG ======= -# 0.30.0.beta1 - May 19 2016 +# 0.40.0.beta - WIP -** SnapKit 0.30.0 ** is a complete re-write to take advantage of modern Swift as well as +** SnapKit 0.50.0 ** is a complete re-write to take advantage of modern Swift 3.0 as well as clean up the API. As such please use with caution and check your apps thoroughly -* All APIs are now accessed via `.snp.*` rather than `.snp_*`. For example you now do `view.snp.makeConstraints {…}` -* Debugging output has been improved to show exact file/line number from which the broken constraint was created. This is an improvement on existing functionality that showed only the file/line number for the make closure. +### Breaking + +* iOS 7.0 support has been removed +* DSL is now accessed through `.snp.*` rather than `.snp_*`. For example `view.snp.makeConstraints { }` +* Constraints are now updated through `update(offset:)`, `update(inset:)` and `update(priority:)` * `.inset()` will no longer take `CGPoint` or `CGSize` as input * `.offset()` will no longer take `CGPoint`, `CGSize`, `EdgeInsets` as input -* Exceptions thrown during constraint creation have been replaced with `fatalError` with better output. +* `updateConstraints` will no longer allow creating new constraints unless there are no existing constraints for the view. If it does generate new constraints it will throw a fatal error. + +### Enhancements + +* Debugging output has been improved to show exact file/line number from which the broken constraint was created +* Exceptions thrown during constraint creation have been replaced with `fatalError` with better output +* Constraints are now installed through `NSLayoutConstraint.activate` and what view they are added to is now deferred to UIKit +* Added `var contentHuggingPriority: CGFloat` to `make` +* Added `var contentCompressionResistancePriority: CGFloat` to `make` # 0.21.0 - May 11 2016 From e02697b2a35b8c7e5f6ebb65f9702bc8c5ed1767 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 6 Aug 2016 22:51:41 +1200 Subject: [PATCH 25/58] Changelog tweaks --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ea4a65..fa69e3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ CHANGELOG # 0.40.0.beta - WIP -** SnapKit 0.50.0 ** is a complete re-write to take advantage of modern Swift 3.0 as well as +**SnapKit 0.40.0** is a complete re-write to take advantage of modern Swift 3.0 as well as clean up the API. As such please use with caution and check your apps thoroughly ### Breaking From 6e8bdde05e62551168713370d91769ead4abdeb1 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 6 Aug 2016 22:53:07 +1200 Subject: [PATCH 26/58] Updated Readme --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index f49428d..f49b762 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ class MyViewController: UIViewController { * [Documentation](http://snapkit.io/docs/) * [F.A.Q.](http://snapkit.io/faq/) -* [Legacy Platforms (iOS 7.0, OS X 10.9)](http://snapkit.io/legacy-platforms/) ## License From a1820376f667f08d04dc276464090a2424896cda Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 6 Aug 2016 22:53:14 +1200 Subject: [PATCH 27/58] Update Podspec --- SnapKit.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SnapKit.podspec b/SnapKit.podspec index 019a640..c68f297 100644 --- a/SnapKit.podspec +++ b/SnapKit.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = 'SnapKit' - s.version = '0.40.0.beta2' + s.version = '0.40.0.beta3' s.license = 'MIT' s.summary = 'Harness the power of auto layout with a simplified, chainable, and compile time safe syntax.' s.homepage = 'https://github.com/SnapKit/SnapKit' s.authors = { 'Robert Payne' => 'robertpayne@me.com' } s.social_media_url = 'http://twitter.com/robertjpayne' - s.source = { :git => 'https://github.com/SnapKit/SnapKit.git', :tag => '0.40.0.beta2' } + s.source = { :git => 'https://github.com/SnapKit/SnapKit.git', :tag => '0.40.0.beta3' } s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.10' From 218efd7d3baac5befae4811b51d829143a1d939a Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 6 Aug 2016 23:24:43 +1200 Subject: [PATCH 28/58] Add more tests --- Tests/Tests.swift | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/Tests/Tests.swift b/Tests/Tests.swift index be74ad0..6e185ad 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -74,8 +74,6 @@ class SnapKitTests: XCTestCase { self.container.addSubview(v1) self.container.addSubview(v2) - print(v1) - v1.snp.makeConstraints { (make) -> Void in make.top.equalTo(v2.snp.top).offset(50) make.left.equalTo(v2.snp.top).offset(50) @@ -224,6 +222,25 @@ class SnapKitTests: XCTestCase { } + func testEdgeConstraints() { + let view = View() + self.container.addSubview(view) + + view.snp.makeConstraints { (make) -> Void in + make.edges.equalTo(self.container).offset(50.0) + } + + XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints") + + + let constraints = self.container.snp_constraints as! [NSLayoutConstraint] + + XCTAssertEqual(constraints[0].constant, 50, "Should be 50") + XCTAssertEqual(constraints[1].constant, 50, "Should be 50") + XCTAssertEqual(constraints[2].constant, 50, "Should be 50") + XCTAssertEqual(constraints[3].constant, 50, "Should be 50") + } + func testSizeConstraints() { let view = View() self.container.addSubview(view) @@ -246,6 +263,23 @@ class SnapKitTests: XCTestCase { XCTAssertEqual(constraints[1].constant, 50, "Should be 50") } + func testCenterConstraints() { + let view = View() + self.container.addSubview(view) + + view.snp.makeConstraints { (make) -> Void in + make.center.equalTo(self.container).offset(50.0) + } + + XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints") + + + let constraints = self.container.snp_constraints as! [NSLayoutConstraint] + + XCTAssertEqual(constraints[0].constant, 50, "Should be 50") + XCTAssertEqual(constraints[1].constant, 50, "Should be 50") + } + func testConstraintIdentifier() { let identifier = "Test-Identifier" let view = View() From 1b712cde8c5b70e315e133fda9f44783ee060a95 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 6 Aug 2016 23:24:55 +1200 Subject: [PATCH 29/58] Remove unecessary print statement --- Source/Constraint.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index b1d4c03..982b413 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -197,8 +197,6 @@ public class Constraint { NSLayoutConstraint.activate(layoutConstraints) view.snp.add(layoutConstraints: layoutConstraints) } - - print(view, layoutConstraints.count, existingLayoutConstraints.count) } internal func deactivateIfNeeded() { From 6aca61ac93b17e3813ae4f887273144d7753c3d3 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 6 Aug 2016 23:25:03 +1200 Subject: [PATCH 30/58] Add `center` to constraint maker --- Source/ConstraintMaker.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/ConstraintMaker.swift b/Source/ConstraintMaker.swift index 94f1556..cefa31f 100644 --- a/Source/ConstraintMaker.swift +++ b/Source/ConstraintMaker.swift @@ -124,6 +124,9 @@ public class ConstraintMaker { public var size: ConstraintMakerExtendable { return self.makeExtendableWithAttributes(.size) } + public var center: ConstraintMakerExtendable { + return self.makeExtendableWithAttributes(.center) + } @available(iOS 8.0, *) public var margins: ConstraintMakerExtendable { From 49d2614836dfede3dc0450e326a9a4fa8a4b6b55 Mon Sep 17 00:00:00 2001 From: Yuki Nagai Date: Sun, 7 Aug 2016 10:05:20 +0900 Subject: [PATCH 31/58] Carthage Support. --- SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme index dec69d9..2f1aed4 100644 --- a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme +++ b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme @@ -22,7 +22,7 @@ From e0395228820928e4432d45cb51f2a5800ee4ef83 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Mon, 8 Aug 2016 11:08:22 +1200 Subject: [PATCH 32/58] Fix OSX deprecation --- Source/ConstraintView+Extensions.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/ConstraintView+Extensions.swift b/Source/ConstraintView+Extensions.swift index 5406cdf..928eabb 100644 --- a/Source/ConstraintView+Extensions.swift +++ b/Source/ConstraintView+Extensions.swift @@ -64,6 +64,7 @@ public extension ConstraintView { public var snp_baseline: ConstraintItem { return self.snp.baseline } @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") + @available(iOS 8.0, OSX 10.11, *) public var snp_lastBaseline: ConstraintItem { return self.snp.lastBaseline } @available(iOS, deprecated:0.40.0, message:"Use newer snp.* syntax.") From 7631964aeeb444fc3c8716c198fd19283b5073f7 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Mon, 8 Aug 2016 11:08:26 +1200 Subject: [PATCH 33/58] =?UTF-8?q?Don=E2=80=99t=20build=20for=20running?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme index dec69d9..2f1aed4 100644 --- a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme +++ b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme @@ -22,7 +22,7 @@ From bd6643ff54794aad58b9f5cd8261d89291960b77 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Tue, 16 Aug 2016 22:53:01 +1200 Subject: [PATCH 34/58] Enable coverage results in tests --- SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme | 3 ++- SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme | 3 ++- SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit tvOS.xcscheme | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme index 15b42fe..410e5f9 100644 --- a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme +++ b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme @@ -40,7 +40,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> diff --git a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme index 2f1aed4..9dc5b70 100644 --- a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme +++ b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme @@ -40,7 +40,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> diff --git a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit tvOS.xcscheme b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit tvOS.xcscheme index ae009c5..3c476cc 100644 --- a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit tvOS.xcscheme +++ b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit tvOS.xcscheme @@ -26,7 +26,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> From a772f0805143cf4d3e0c4298325bce6722d2e474 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Tue, 16 Aug 2016 22:53:17 +1200 Subject: [PATCH 35/58] Remove unused code --- Source/Constraint.swift | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 982b413..5455932 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -207,18 +207,18 @@ public class Constraint { } } -extension Constraint: Hashable { - - public var hashValue: Int { - return self.layoutConstraints.hashValue - } - -} - -public func ==(lhs: Constraint, rhs: Constraint) -> Bool { - return (lhs.from == rhs.from && - lhs.to == rhs.to && - lhs.relation == rhs.relation && - lhs.multiplier.constraintMultiplierTargetValue == rhs.multiplier.constraintMultiplierTargetValue && - lhs.priority.constraintPriorityTargetValue == rhs.priority.constraintPriorityTargetValue) -} +//extension Constraint: Hashable { +// +// public var hashValue: Int { +// return self.layoutConstraints.hashValue +// } +// +//} +// +//public func ==(lhs: Constraint, rhs: Constraint) -> Bool { +// return (lhs.from == rhs.from && +// lhs.to == rhs.to && +// lhs.relation == rhs.relation && +// lhs.multiplier.constraintMultiplierTargetValue == rhs.multiplier.constraintMultiplierTargetValue && +// lhs.priority.constraintPriorityTargetValue == rhs.priority.constraintPriorityTargetValue) +//} From 79137bce68404852e62deb90b4da374033220e65 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Tue, 16 Aug 2016 22:53:27 +1200 Subject: [PATCH 36/58] Xcode 8 - Beta 6 --- Source/ConstraintMaker.swift | 14 +++++++------- Source/ConstraintView+Extensions.swift | 8 ++++---- Source/ConstraintViewDSL.swift | 8 ++++---- Source/Debugging.swift | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Source/ConstraintMaker.swift b/Source/ConstraintMaker.swift index cefa31f..0749104 100644 --- a/Source/ConstraintMaker.swift +++ b/Source/ConstraintMaker.swift @@ -152,9 +152,9 @@ public class ConstraintMaker { return ConstraintMakerExtendable(description) } - internal static func prepareConstraints(view: ConstraintView, closure: @noescape(make: ConstraintMaker) -> Void) -> [Constraint] { + internal static func prepareConstraints(view: ConstraintView, closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] { let maker = ConstraintMaker(view: view) - closure(make: maker) + closure(maker) let constraints = maker.descriptions .map { $0.constraint } .filter { $0 != nil } @@ -162,9 +162,9 @@ public class ConstraintMaker { return constraints } - internal static func makeConstraints(view: ConstraintView, closure: @noescape(make: ConstraintMaker) -> Void) { + internal static func makeConstraints(view: ConstraintView, closure: (_ make: ConstraintMaker) -> Void) { let maker = ConstraintMaker(view: view) - closure(make: maker) + closure(maker) let constraints = maker.descriptions .map { $0.constraint } .filter { $0 != nil } @@ -174,14 +174,14 @@ public class ConstraintMaker { } } - internal static func remakeConstraints(view: ConstraintView, closure: @noescape(make: ConstraintMaker) -> Void) { + internal static func remakeConstraints(view: ConstraintView, closure: (_ make: ConstraintMaker) -> Void) { self.removeConstraints(view: view) self.makeConstraints(view: view, closure: closure) } - internal static func updateConstraints(view: ConstraintView, closure: @noescape(make: ConstraintMaker) -> Void) { + internal static func updateConstraints(view: ConstraintView, closure: (_ make: ConstraintMaker) -> Void) { let maker = ConstraintMaker(view: view) - closure(make: maker) + closure(maker) let constraints = maker.descriptions .map { $0.constraint } .filter { $0 != nil } diff --git a/Source/ConstraintView+Extensions.swift b/Source/ConstraintView+Extensions.swift index 928eabb..b9634e7 100644 --- a/Source/ConstraintView+Extensions.swift +++ b/Source/ConstraintView+Extensions.swift @@ -121,22 +121,22 @@ public extension ConstraintView { public var snp_centerWithinMargins: ConstraintItem { return self.snp.centerWithinMargins } @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") - public func snp_prepareConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) -> [Constraint] { + public func snp_prepareConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] { return self.snp.prepareConstraints(closure) } @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") - public func snp_makeConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { + public func snp_makeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { self.snp.makeConstraints(closure) } @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") - public func snp_remakeConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { + public func snp_remakeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { self.snp.remakeConstraints(closure) } @available(*, deprecated:0.40.0, message:"Use newer snp.* syntax.") - public func snp_updateConstraints(_ closure: @noescape(make: ConstraintMaker) -> Void) { + public func snp_updateConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { self.snp.updateConstraints(closure) } diff --git a/Source/ConstraintViewDSL.swift b/Source/ConstraintViewDSL.swift index 7d5f136..ef3d6b1 100644 --- a/Source/ConstraintViewDSL.swift +++ b/Source/ConstraintViewDSL.swift @@ -148,19 +148,19 @@ public struct ConstraintViewDSL { } @discardableResult - public func prepareConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) -> [Constraint] { + public func prepareConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] { return ConstraintMaker.prepareConstraints(view: self.view, closure: closure) } - public func makeConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) { + public func makeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { ConstraintMaker.makeConstraints(view: self.view, closure: closure) } - public func remakeConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) { + public func remakeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { ConstraintMaker.remakeConstraints(view: self.view, closure: closure) } - public func updateConstraints(_ closure: @noescape (make: ConstraintMaker) -> Void) { + public func updateConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { ConstraintMaker.updateConstraints(view: self.view, closure: closure) } diff --git a/Source/Debugging.swift b/Source/Debugging.swift index ff3a8a2..be8bb9e 100644 --- a/Source/Debugging.swift +++ b/Source/Debugging.swift @@ -138,10 +138,10 @@ private func conditionalOptional(from object: T) -> Optional { } private func descriptionForObject(_ object: AnyObject) -> String { - let pointerDescription = NSString(format: "%p", UInt(ObjectIdentifier(object))) + let pointerDescription = String(format: "%p", UInt(bitPattern: ObjectIdentifier(object))) var desc = "" - desc += object.dynamicType.description() + desc += type(of: object).description() if let object = object as? ConstraintView { desc += ":\(object.snp.label ?? pointerDescription)" From 7e8c1732242de2228988001efc71db6ad7bb3415 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Tue, 16 Aug 2016 23:24:14 +1200 Subject: [PATCH 37/58] Allow implied superview for equalTo(constant) --- Source/Constraint.swift | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 5455932..d0fae6f 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -87,11 +87,16 @@ public class Constraint { // get layout to #if os(iOS) || os(tvOS) - let layoutTo: AnyObject? = self.to.view ?? self.to.layoutSupport + var layoutTo: AnyObject? = self.to.view ?? self.to.layoutSupport #else - let layoutTo: AnyObject? = self.to.view + var layoutTo: AnyObject? = self.to.view #endif + // use superview if possible + if layoutTo == nil && layoutToAttribute != .width && layoutToAttribute != .height { + layoutTo = layoutFrom.superview + } + // create layout constraint let layoutConstraint = LayoutConstraint( item: layoutFrom, @@ -206,19 +211,3 @@ public class Constraint { view.snp.remove(layoutConstraints: layoutConstraints) } } - -//extension Constraint: Hashable { -// -// public var hashValue: Int { -// return self.layoutConstraints.hashValue -// } -// -//} -// -//public func ==(lhs: Constraint, rhs: Constraint) -> Bool { -// return (lhs.from == rhs.from && -// lhs.to == rhs.to && -// lhs.relation == rhs.relation && -// lhs.multiplier.constraintMultiplierTargetValue == rhs.multiplier.constraintMultiplierTargetValue && -// lhs.priority.constraintPriorityTargetValue == rhs.priority.constraintPriorityTargetValue) -//} From fbd807fd095a8c00dcefdcae7bab77e8dea8cea9 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Tue, 16 Aug 2016 23:24:48 +1200 Subject: [PATCH 38/58] Alter how insets work when used as implied constant Using make.left.bottom.equalTo(UIEdgeInsets) will now invert the right and bottom edge. --- Source/ConstraintConstantTarget.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/ConstraintConstantTarget.swift b/Source/ConstraintConstantTarget.swift index 40ed274..46bd3ed 100644 --- a/Source/ConstraintConstantTarget.swift +++ b/Source/ConstraintConstantTarget.swift @@ -103,17 +103,17 @@ extension ConstraintConstantTarget { case .top, .topMargin, .centerY, .centerYWithinMargins, .lastBaseline, .firstBaseline: return value.top case .right, .rightMargin: - return value.right + return -value.right case .bottom, .bottomMargin: - return value.bottom + return -value.bottom case .leading, .leadingMargin: return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : -value.right case .trailing, .trailingMargin: return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.right : -value.left case .width: - return -value.left + value.right + return -(value.left + value.right) case .height: - return -value.top + value.bottom + return -(value.top + value.bottom) case .notAnAttribute: return 0.0 } From ae3012f884922d36f3021b85924df9a68c68c96b Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Tue, 16 Aug 2016 23:24:51 +1200 Subject: [PATCH 39/58] Add more tests --- Tests/Tests.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 6e185ad..27585de 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -68,6 +68,28 @@ class SnapKitTests: XCTestCase { } + func testMakeImpliedSuperviewConstraints() { + let v1 = View() + let v2 = View() + self.container.addSubview(v1) + self.container.addSubview(v2) + + v1.snp.makeConstraints { (make) -> Void in + make.top.equalTo(50.0) + make.left.equalTo(50.0) + return + } + + XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed") + + v2.snp.makeConstraints { (make) -> Void in + make.edges.equalTo(v1) + return + } + + XCTAssertEqual(self.container.snp_constraints.count, 6, "Should have 6 constraints installed") + } + func testUpdateConstraints() { let v1 = View() let v2 = View() From 4bd29e82fb0c25db9da7bee267a8d6e02f82f44f Mon Sep 17 00:00:00 2001 From: Yuki Nagai Date: Mon, 29 Aug 2016 15:23:22 +0900 Subject: [PATCH 40/58] Make ConstraintDescription.constraint lazy --- Source/ConstraintDescription.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/ConstraintDescription.swift b/Source/ConstraintDescription.swift index 6eae505..d961fb5 100644 --- a/Source/ConstraintDescription.swift +++ b/Source/ConstraintDescription.swift @@ -39,7 +39,7 @@ public class ConstraintDescription { internal var multiplier: ConstraintMultiplierTarget = 1.0 internal var constant: ConstraintConstantTarget = 0.0 internal var priority: ConstraintPriorityTarget = 1000.0 - internal var constraint: Constraint? { + internal lazy var constraint: Constraint? = { guard let relation = self.relation, let related = self.related, let sourceLocation = self.sourceLocation else { @@ -57,7 +57,7 @@ public class ConstraintDescription { constant: self.constant, priority: self.priority ) - } + }() // MARK: Initialization From 43c0f2b4874869dccc674c1b60b1bcdd1dea9944 Mon Sep 17 00:00:00 2001 From: Madhava Jay Date: Wed, 31 Aug 2016 13:40:54 +0200 Subject: [PATCH 41/58] Fixed testSizeConstraints test as per suggestion: https://github.com/SnapKit/SnapKit/pull/243 --- Tests/Tests.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 27585de..fef7af9 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -276,11 +276,15 @@ class SnapKitTests: XCTestCase { XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints") - let constraints = view.snp_constraints as! [NSLayoutConstraint] - - XCTAssertEqual(constraints[0].firstAttribute.rawValue, NSLayoutAttribute.width.rawValue, "Should be width") - XCTAssertEqual(constraints[1].firstAttribute.rawValue, NSLayoutAttribute.height.rawValue, "Should be height") + + // no guarantee which order the constraints are in, but we should test their couple + let widthHeight = (NSLayoutAttribute.width.rawValue, NSLayoutAttribute.height.rawValue) + let heightWidth = (widthHeight.1, widthHeight.0) + let firstSecond = (constraints[0].firstAttribute.rawValue, constraints[1].firstAttribute.rawValue) + + // constraint values are correct in either width, height or height, width order + XCTAssertTrue(firstSecond == widthHeight || firstSecond == heightWidth, "2 contraint values should match") XCTAssertEqual(constraints[0].constant, 50, "Should be 50") XCTAssertEqual(constraints[1].constant, 50, "Should be 50") } From fc298aeaf41ba00088bb9d353acfe26fb10ccf9b Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Fri, 2 Sep 2016 00:27:26 +1200 Subject: [PATCH 42/58] 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") -//// } } From 0219f730a734fd4d2bc25ae188bd658a2a03e86d Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Fri, 2 Sep 2016 00:29:06 +1200 Subject: [PATCH 43/58] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa69e3e..bcbe628 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ clean up the API. As such please use with caution and check your apps thoroughly * Constraints are now installed through `NSLayoutConstraint.activate` and what view they are added to is now deferred to UIKit * Added `var contentHuggingPriority: CGFloat` to `make` * Added `var contentCompressionResistancePriority: CGFloat` to `make` +* Added support for `UILayoutGuide` via `make.left.equalTo(guide.snp.top)` # 0.21.0 - May 11 2016 From 17db4dee155b75f91930349abff69775cb66c64d Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Fri, 2 Sep 2016 00:54:18 +1200 Subject: [PATCH 44/58] Increase test coverage and fix bugs --- Source/ConstraintInsetTarget.swift | 18 +++--- Tests/Tests.swift | 89 ++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 11 deletions(-) diff --git a/Source/ConstraintInsetTarget.swift b/Source/ConstraintInsetTarget.swift index 7ca58a9..ba8a0f3 100644 --- a/Source/ConstraintInsetTarget.swift +++ b/Source/ConstraintInsetTarget.swift @@ -52,25 +52,21 @@ extension ConstraintInsets: ConstraintInsetTarget { extension ConstraintInsetTarget { internal var constraintInsetTargetValue: ConstraintInsets { - let insets: ConstraintInsets - if let amount = self as? ConstraintInsets { - insets = amount + return amount } else if let amount = self as? Float { - insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) + return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) } else if let amount = self as? Double { - insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) + return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) } else if let amount = self as? CGFloat { - insets = ConstraintInsets(top: amount, left: amount, bottom: amount, right: amount) + return ConstraintInsets(top: amount, left: amount, bottom: amount, right: amount) } else if let amount = self as? Int { - insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) + return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) } else if let amount = self as? UInt { - insets = ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) + return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) } else { - insets = ConstraintInsets(top: 0, left: 0, bottom: 0, right: 0) + return ConstraintInsets(top: 0, left: 0, bottom: 0, right: 0) } - - return ConstraintInsets(top: insets.top, left: insets.left, bottom: -insets.bottom, right: -insets.right) } } diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 4eebb8f..a5f683c 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -115,6 +115,7 @@ class SnapKitTests: XCTestCase { } + func testRemakeConstraints() { let v1 = View() let v2 = View() @@ -265,6 +266,94 @@ class SnapKitTests: XCTestCase { XCTAssertEqual(constraints[3].constant, 50, "Should be 50") } + func testUpdateReferencedConstraints() { + let v1 = View() + let v2 = View() + self.container.addSubview(v1) + self.container.addSubview(v2) + + var c1: Constraint! = nil + var c2: Constraint! = nil + + v1.snp.makeConstraints { (make) -> Void in + c1 = make.top.equalTo(v2.snp.top).offset(50).constraint + c2 = make.left.equalTo(v2.snp.top).offset(25).constraint + return + } + + XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints") + + let before = (self.container.snp_constraints as! [NSLayoutConstraint]).sorted { $0.constant > $1.constant } + + XCTAssertEqual(before[0].constant, 50, "Should be 50") + XCTAssertEqual(before[1].constant, 25, "Should be 25") + + c1.update(offset: 15) + c2.update(offset: 20) + + XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints") + + XCTAssertEqual(before[0].constant, 15, "Should be 15") + XCTAssertEqual(before[1].constant, 20, "Should be 20") + + } + + func testInsetsAsConstraintsConstant() { + let view = View() + self.container.addSubview(view) + + view.snp.makeConstraints { (make) -> Void in + make.edges.equalTo(self.container).inset(50.0) + } + + XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints") + + let constraints = (self.container.snp_constraints as! [NSLayoutConstraint]).sorted { $0.constant > $1.constant } + + XCTAssertEqual(constraints[0].constant, 50, "Should be 50") + XCTAssertEqual(constraints[1].constant, 50, "Should be 50") + XCTAssertEqual(constraints[2].constant, -50, "Should be -50") + XCTAssertEqual(constraints[3].constant, -50, "Should be -50") + } + + func testUIEdgeInsetsAsImpliedEqualToConstraints() { + let view = View() + self.container.addSubview(view) + + view.snp.makeConstraints { (make) -> Void in + make.edges.equalTo(UIEdgeInsets(top: 25, left: 25, bottom: 25, right: 25)) + } + + XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints") + + + let constraints = (self.container.snp_constraints as! [NSLayoutConstraint]).sorted { $0.constant > $1.constant } + + XCTAssertEqual(constraints[0].constant, 25, "Should be 25") + XCTAssertEqual(constraints[1].constant, 25, "Should be 25") + XCTAssertEqual(constraints[2].constant, -25, "Should be -25") + XCTAssertEqual(constraints[3].constant, -25, "Should be -25") + } + + func testUIEdgeInsetsAsConstraintsConstant() { + let view = View() + self.container.addSubview(view) + + view.snp.makeConstraints { (make) -> Void in + make.edges.equalTo(self.container).inset(UIEdgeInsets(top: 25, left: 25, bottom: 25, right: 25)) + } + + XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints") + + + let constraints = (self.container.snp_constraints as! [NSLayoutConstraint]).sorted { $0.constant > $1.constant } + + XCTAssertEqual(constraints[0].constant, 25, "Should be 25") + XCTAssertEqual(constraints[1].constant, 25, "Should be 25") + XCTAssertEqual(constraints[2].constant, -25, "Should be -25") + XCTAssertEqual(constraints[3].constant, -25, "Should be -25") + } + func testSizeConstraints() { let view = View() self.container.addSubview(view) From c1ae9c28ac896d7545114d5217d0c53d0ed95eb0 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Fri, 2 Sep 2016 00:57:40 +1200 Subject: [PATCH 45/58] More tests --- Tests/Tests.swift | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Tests/Tests.swift b/Tests/Tests.swift index a5f683c..4d5bf4f 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -276,25 +276,33 @@ class SnapKitTests: XCTestCase { var c2: Constraint! = nil v1.snp.makeConstraints { (make) -> Void in - c1 = make.top.equalTo(v2.snp.top).offset(50).constraint - c2 = make.left.equalTo(v2.snp.top).offset(25).constraint + c1 = make.top.equalTo(v2).offset(50).constraint + c2 = make.bottom.equalTo(v2).offset(25).constraint return } XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints") - let before = (self.container.snp_constraints as! [NSLayoutConstraint]).sorted { $0.constant > $1.constant } + let constraints = (self.container.snp_constraints as! [NSLayoutConstraint]).sorted { $0.constant > $1.constant } - XCTAssertEqual(before[0].constant, 50, "Should be 50") - XCTAssertEqual(before[1].constant, 25, "Should be 25") + XCTAssertEqual(constraints[0].constant, 50, "Should be 50") + XCTAssertEqual(constraints[1].constant, 25, "Should be 25") c1.update(offset: 15) c2.update(offset: 20) XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints") - XCTAssertEqual(before[0].constant, 15, "Should be 15") - XCTAssertEqual(before[1].constant, 20, "Should be 20") + XCTAssertEqual(constraints[0].constant, 15, "Should be 15") + XCTAssertEqual(constraints[1].constant, 20, "Should be 20") + + c1.update(inset: 15) + c2.update(inset: 20) + + XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints") + + XCTAssertEqual(constraints[0].constant, 15, "Should be 15") + XCTAssertEqual(constraints[1].constant, -20, "Should be -20") } From 2f803657af8bd5f6ebaa4b1932b1b5aa7571dcf2 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Fri, 2 Sep 2016 00:58:22 +1200 Subject: [PATCH 46/58] Update podspec --- SnapKit.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SnapKit.podspec b/SnapKit.podspec index c68f297..3fe34ce 100644 --- a/SnapKit.podspec +++ b/SnapKit.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = 'SnapKit' - s.version = '0.40.0.beta3' + s.version = '0.40.0.beta4' s.license = 'MIT' s.summary = 'Harness the power of auto layout with a simplified, chainable, and compile time safe syntax.' s.homepage = 'https://github.com/SnapKit/SnapKit' s.authors = { 'Robert Payne' => 'robertpayne@me.com' } s.social_media_url = 'http://twitter.com/robertjpayne' - s.source = { :git => 'https://github.com/SnapKit/SnapKit.git', :tag => '0.40.0.beta3' } + s.source = { :git => 'https://github.com/SnapKit/SnapKit.git', :tag => '0.40.0.beta4' } s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.10' From 514ec790421a997882cd3e6c00cd544d647a6adc Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Fri, 2 Sep 2016 01:23:25 +1200 Subject: [PATCH 47/58] Add support for edges to margins and margins to edges --- Source/Constraint.swift | 37 ++++++++++++++++++++++++- Source/ConstraintMakerRelatable.swift | 4 ++- Tests/Tests.swift | 40 +++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index e9abd75..5d43731 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -80,7 +80,42 @@ public class Constraint { for layoutFromAttribute in layoutFromAttributes { // get layout to attribute - let layoutToAttribute = (layoutToAttributes.count > 0) ? layoutToAttributes[0] : layoutFromAttribute + let layoutToAttribute: NSLayoutAttribute + if layoutToAttributes.count > 1 { + if self.from.attributes == .edges && self.to.attributes == .margins { + switch layoutFromAttribute { + case .left: + layoutToAttribute = .leftMargin + case .right: + layoutToAttribute = .rightMargin + case .top: + layoutToAttribute = .topMargin + case .bottom: + layoutToAttribute = .bottomMargin + default: + fatalError() + } + } else if self.from.attributes == .margins && self.to.attributes == .edges { + switch layoutFromAttribute { + case .leftMargin: + layoutToAttribute = .left + case .rightMargin: + layoutToAttribute = .right + case .topMargin: + layoutToAttribute = .top + case .bottomMargin: + layoutToAttribute = .bottom + default: + fatalError() + } + } else { + layoutToAttribute = layoutToAttributes[0] + } + } else if layoutToAttributes.count == 1 { + layoutToAttribute = layoutToAttributes[0] + } else { + layoutToAttribute = layoutFromAttribute + } // get layout constant let layoutConstant: CGFloat = self.constant.constraintConstantTargetValueFor(layoutAttribute: layoutToAttribute) diff --git a/Source/ConstraintMakerRelatable.swift b/Source/ConstraintMakerRelatable.swift index c4141be..7a2968d 100644 --- a/Source/ConstraintMakerRelatable.swift +++ b/Source/ConstraintMakerRelatable.swift @@ -43,7 +43,9 @@ public class ConstraintMakerRelatable { if let other = other as? ConstraintItem { guard other.attributes == ConstraintAttributes.none || other.attributes.layoutAttributes.count <= 1 || - other.attributes.layoutAttributes == self.description.attributes.layoutAttributes else { + other.attributes.layoutAttributes == self.description.attributes.layoutAttributes || + other.attributes == .edges && self.description.attributes == .margins || + other.attributes == .margins && self.description.attributes == .edges else { fatalError("Cannot constraint to multiple non identical attributes. (\(file), \(line))"); } diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 4d5bf4f..8b502b2 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -418,4 +418,44 @@ class SnapKitTests: XCTestCase { XCTAssertEqual(constraints[0].identifier, identifier, "Identifier should be 'Test'") } + func testEdgesToMargins() { + var fromAttributes = Set() + var toAttributes = Set() + + let view = View() + self.container.addSubview(view) + + view.snp.remakeConstraints { (make) -> Void in + make.edges.equalTo(self.container.snp.margins) + } + + XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints") + + for constraint in (container.snp_constraints as! [NSLayoutConstraint]) { + fromAttributes.insert(constraint.firstAttribute) + toAttributes.insert(constraint.secondAttribute) + } + + XCTAssert(fromAttributes == [.top, .left, .bottom, .right]) + XCTAssert(toAttributes == [.topMargin, .leftMargin, .bottomMargin, .rightMargin]) + + fromAttributes.removeAll() + toAttributes.removeAll() + + view.snp.remakeConstraints { (make) -> Void in + make.margins.equalTo(self.container.snp.edges) + } + + XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints") + + for constraint in (container.snp_constraints as! [NSLayoutConstraint]) { + fromAttributes.insert(constraint.firstAttribute) + toAttributes.insert(constraint.secondAttribute) + } + + XCTAssert(toAttributes == [.top, .left, .bottom, .right]) + XCTAssert(fromAttributes == [.topMargin, .leftMargin, .bottomMargin, .rightMargin]) + + } + } From 2764642a2dfaec60c357cc7ed9687ff270db399b Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Fri, 2 Sep 2016 01:39:08 +1200 Subject: [PATCH 48/58] Tweaks for OSX support --- SnapKit.xcodeproj/project.pbxproj | 48 ++++++++----- Source/Constraint.swift | 72 ++++++++++--------- Source/ConstraintConstantTarget.swift | 8 +-- Source/ConstraintLayoutGuide.swift | 36 ++++++++++ ...L.swift => ConstraintLayoutGuideDSL.swift} | 6 +- Source/ConstraintLayoutSupport.swift | 36 ++++++++++ ...swift => ConstraintLayoutSupportDSL.swift} | 6 +- Source/UILayoutGuide+Extensions.swift | 6 +- Source/UILayoutSupport+Extensions.swift | 6 +- Tests/Tests.swift | 44 ++++++------ 10 files changed, 182 insertions(+), 86 deletions(-) create mode 100644 Source/ConstraintLayoutGuide.swift rename Source/{UILayoutGuideDSL.swift => ConstraintLayoutGuideDSL.swift} (89%) create mode 100644 Source/ConstraintLayoutSupport.swift rename Source/{UILayoutSupportDSL.swift => ConstraintLayoutSupportDSL.swift} (91%) diff --git a/SnapKit.xcodeproj/project.pbxproj b/SnapKit.xcodeproj/project.pbxproj index f85712c..6aadaca 100644 --- a/SnapKit.xcodeproj/project.pbxproj +++ b/SnapKit.xcodeproj/project.pbxproj @@ -80,9 +80,9 @@ 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 /* 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 */; }; + EE235FC31C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift */; }; + EE235FC41C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift */; }; + EE235FC51C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* ConstraintLayoutSupportDSL.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 */; }; @@ -94,10 +94,10 @@ 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 */; }; + EEF68F9E1D78492400980C26 /* ConstraintLayoutGuideDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68F9D1D78492400980C26 /* ConstraintLayoutGuideDSL.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 */; }; + EEF68FAB1D784E3800980C26 /* ConstraintLayoutGuideDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68F9D1D78492400980C26 /* ConstraintLayoutGuideDSL.swift */; }; + EEF68FAC1D784E3800980C26 /* ConstraintLayoutGuideDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68F9D1D78492400980C26 /* ConstraintLayoutGuideDSL.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 */; }; @@ -106,6 +106,12 @@ 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 */; }; + EEF68FBC1D78653000980C26 /* ConstraintLayoutGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FBB1D78653000980C26 /* ConstraintLayoutGuide.swift */; }; + EEF68FBD1D78653000980C26 /* ConstraintLayoutGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FBB1D78653000980C26 /* ConstraintLayoutGuide.swift */; }; + EEF68FBE1D78653000980C26 /* ConstraintLayoutGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FBB1D78653000980C26 /* ConstraintLayoutGuide.swift */; }; + EEF68FC01D7865AA00980C26 /* ConstraintLayoutSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FBF1D7865AA00980C26 /* ConstraintLayoutSupport.swift */; }; + EEF68FC11D7865AA00980C26 /* ConstraintLayoutSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FBF1D7865AA00980C26 /* ConstraintLayoutSupport.swift */; }; + EEF68FC21D7865AA00980C26 /* ConstraintLayoutSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FBF1D7865AA00980C26 /* ConstraintLayoutSupport.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -145,7 +151,7 @@ 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 /* UILayoutSupportDSL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UILayoutSupportDSL.swift; sourceTree = ""; }; + EE235FBF1C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintLayoutSupportDSL.swift; sourceTree = ""; }; EE235FC61C5785E200C08960 /* ConstraintView+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConstraintView+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; }; @@ -157,10 +163,12 @@ 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 = ""; }; + EEF68F9D1D78492400980C26 /* ConstraintLayoutGuideDSL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintLayoutGuideDSL.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 = ""; }; + EEF68FBB1D78653000980C26 /* ConstraintLayoutGuide.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintLayoutGuide.swift; sourceTree = ""; }; + EEF68FBF1D7865AA00980C26 /* ConstraintLayoutSupport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintLayoutSupport.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -252,8 +260,8 @@ children = ( EEF68FA51D784A5300980C26 /* ConstraintDSL.swift */, EE235FBE1C5785DC00C08960 /* ConstraintViewDSL.swift */, - EEF68F9D1D78492400980C26 /* UILayoutGuideDSL.swift */, - EE235FBF1C5785DC00C08960 /* UILayoutSupportDSL.swift */, + EEF68F9D1D78492400980C26 /* ConstraintLayoutGuideDSL.swift */, + EE235FBF1C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift */, ); name = DSLs; sourceTree = ""; @@ -292,6 +300,8 @@ EE235F641C5785C600C08960 /* ConstraintInsets.swift */, EE235F651C5785C600C08960 /* ConstraintConfig.swift */, EE235F661C5785C600C08960 /* ConstraintView.swift */, + EEF68FBB1D78653000980C26 /* ConstraintLayoutGuide.swift */, + EEF68FBF1D7865AA00980C26 /* ConstraintLayoutSupport.swift */, EE235F681C5785C600C08960 /* ConstraintRelation.swift */, EE235F6A1C5785C600C08960 /* ConstraintAttributes.swift */, EE235F6B1C5785C600C08960 /* ConstraintItem.swift */, @@ -602,14 +612,16 @@ EE235FB91C5785D400C08960 /* ConstraintMakerRelatable.swift in Sources */, EE235F861C5785C600C08960 /* ConstraintAttributes.swift in Sources */, EE235FA11C5785CE00C08960 /* ConstraintOffsetTarget.swift in Sources */, - EEF68FAB1D784E3800980C26 /* UILayoutGuideDSL.swift in Sources */, + EEF68FAB1D784E3800980C26 /* ConstraintLayoutGuideDSL.swift in Sources */, EE235FB61C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */, + EEF68FBD1D78653000980C26 /* ConstraintLayoutGuide.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 */, + EEF68FC11D7865AA00980C26 /* ConstraintLayoutSupport.swift in Sources */, EEF68FB11D784FB100980C26 /* UILayoutGuide+Extensions.swift in Sources */, EE235F771C5785C600C08960 /* ConstraintConfig.swift in Sources */, EE235F6E1C5785C600C08960 /* Constraint.swift in Sources */, @@ -620,7 +632,7 @@ EE235F9E1C5785CE00C08960 /* ConstraintMultiplierTarget.swift in Sources */, EE235FC11C5785DC00C08960 /* ConstraintViewDSL.swift in Sources */, EE235F601C5785BC00C08960 /* Debugging.swift in Sources */, - EE235FC41C5785DC00C08960 /* UILayoutSupportDSL.swift in Sources */, + EE235FC41C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift in Sources */, EE235F801C5785C600C08960 /* ConstraintRelation.swift in Sources */, EEF68FB51D784FBA00980C26 /* UILayoutSupport+Extensions.swift in Sources */, EE235F711C5785C600C08960 /* ConstraintDescription.swift in Sources */, @@ -646,14 +658,16 @@ EE235FB81C5785D400C08960 /* ConstraintMakerRelatable.swift in Sources */, EE235F851C5785C600C08960 /* ConstraintAttributes.swift in Sources */, EE235FA01C5785CE00C08960 /* ConstraintOffsetTarget.swift in Sources */, - EEF68F9E1D78492400980C26 /* UILayoutGuideDSL.swift in Sources */, + EEF68F9E1D78492400980C26 /* ConstraintLayoutGuideDSL.swift in Sources */, EE235FB51C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */, + EEF68FBC1D78653000980C26 /* ConstraintLayoutGuide.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 */, + EEF68FC01D7865AA00980C26 /* ConstraintLayoutSupport.swift in Sources */, EEF68FB01D784FB100980C26 /* UILayoutGuide+Extensions.swift in Sources */, EE235F761C5785C600C08960 /* ConstraintConfig.swift in Sources */, EE235F6D1C5785C600C08960 /* Constraint.swift in Sources */, @@ -664,7 +678,7 @@ EE235F9D1C5785CE00C08960 /* ConstraintMultiplierTarget.swift in Sources */, EE235FC01C5785DC00C08960 /* ConstraintViewDSL.swift in Sources */, EE235F5F1C5785BC00C08960 /* Debugging.swift in Sources */, - EE235FC31C5785DC00C08960 /* UILayoutSupportDSL.swift in Sources */, + EE235FC31C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift in Sources */, EE235F7F1C5785C600C08960 /* ConstraintRelation.swift in Sources */, EEF68FB41D784FBA00980C26 /* UILayoutSupport+Extensions.swift in Sources */, EE235F701C5785C600C08960 /* ConstraintDescription.swift in Sources */, @@ -690,14 +704,16 @@ EE235FBA1C5785D400C08960 /* ConstraintMakerRelatable.swift in Sources */, EE235F871C5785C600C08960 /* ConstraintAttributes.swift in Sources */, EE235FA21C5785CE00C08960 /* ConstraintOffsetTarget.swift in Sources */, - EEF68FAC1D784E3800980C26 /* UILayoutGuideDSL.swift in Sources */, + EEF68FAC1D784E3800980C26 /* ConstraintLayoutGuideDSL.swift in Sources */, EE235FB71C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */, + EEF68FBE1D78653000980C26 /* ConstraintLayoutGuide.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 */, + EEF68FC21D7865AA00980C26 /* ConstraintLayoutSupport.swift in Sources */, EEF68FB21D784FB100980C26 /* UILayoutGuide+Extensions.swift in Sources */, EE235F781C5785C600C08960 /* ConstraintConfig.swift in Sources */, EE235F6F1C5785C600C08960 /* Constraint.swift in Sources */, @@ -708,7 +724,7 @@ EE235F9F1C5785CE00C08960 /* ConstraintMultiplierTarget.swift in Sources */, EE235FC21C5785DC00C08960 /* ConstraintViewDSL.swift in Sources */, EE235F611C5785BC00C08960 /* Debugging.swift in Sources */, - EE235FC51C5785DC00C08960 /* UILayoutSupportDSL.swift in Sources */, + EE235FC51C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift in Sources */, EE235F811C5785C600C08960 /* ConstraintRelation.swift in Sources */, EEF68FB61D784FBA00980C26 /* UILayoutSupport+Extensions.swift in Sources */, EE235F721C5785C600C08960 /* ConstraintDescription.swift in Sources */, diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 5d43731..c6e5e01 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -81,41 +81,49 @@ public class Constraint { for layoutFromAttribute in layoutFromAttributes { // get layout to attribute let layoutToAttribute: NSLayoutAttribute - if layoutToAttributes.count > 1 { - if self.from.attributes == .edges && self.to.attributes == .margins { - switch layoutFromAttribute { - case .left: - layoutToAttribute = .leftMargin - case .right: - layoutToAttribute = .rightMargin - case .top: - layoutToAttribute = .topMargin - case .bottom: - layoutToAttribute = .bottomMargin - default: - fatalError() + #if os(iOS) || os(tvOS) + if layoutToAttributes.count > 1 { + if self.from.attributes == .edges && self.to.attributes == .margins { + switch layoutFromAttribute { + case .left: + layoutToAttribute = .leftMargin + case .right: + layoutToAttribute = .rightMargin + case .top: + layoutToAttribute = .topMargin + case .bottom: + layoutToAttribute = .bottomMargin + default: + fatalError() + } + } else if self.from.attributes == .margins && self.to.attributes == .edges { + switch layoutFromAttribute { + case .leftMargin: + layoutToAttribute = .left + case .rightMargin: + layoutToAttribute = .right + case .topMargin: + layoutToAttribute = .top + case .bottomMargin: + layoutToAttribute = .bottom + default: + fatalError() + } + } else { + layoutToAttribute = layoutToAttributes[0] } - } else if self.from.attributes == .margins && self.to.attributes == .edges { - switch layoutFromAttribute { - case .leftMargin: - layoutToAttribute = .left - case .rightMargin: - layoutToAttribute = .right - case .topMargin: - layoutToAttribute = .top - case .bottomMargin: - layoutToAttribute = .bottom - default: - fatalError() - } - } else { + } else if layoutToAttributes.count == 1 { layoutToAttribute = layoutToAttributes[0] + } else { + layoutToAttribute = layoutFromAttribute } - } else if layoutToAttributes.count == 1 { - layoutToAttribute = layoutToAttributes[0] - } else { - layoutToAttribute = layoutFromAttribute - } + #else + if layoutToAttributes.count > 0 { + layoutToAttribute = layoutToAttributes[0] + } else { + layoutToAttribute = layoutFromAttribute + } + #endif // get layout constant let layoutConstant: CGFloat = self.constant.constraintConstantTargetValueFor(layoutAttribute: layoutToAttribute) diff --git a/Source/ConstraintConstantTarget.swift b/Source/ConstraintConstantTarget.swift index 46bd3ed..8a32519 100644 --- a/Source/ConstraintConstantTarget.swift +++ b/Source/ConstraintConstantTarget.swift @@ -124,17 +124,17 @@ extension ConstraintConstantTarget { case .top, .centerY, .lastBaseline, .firstBaseline: return value.top case .right: - return value.right + return -value.right case .bottom: - return value.bottom + return -value.bottom case .leading: return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : -value.right case .trailing: return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.right : -value.left case .width: - return -value.left + value.right + return -(value.left + value.right) case .height: - return -value.top + value.bottom + return -(value.top + value.bottom) case .notAnAttribute: return 0.0 } diff --git a/Source/ConstraintLayoutGuide.swift b/Source/ConstraintLayoutGuide.swift new file mode 100644 index 0000000..f6eba82 --- /dev/null +++ b/Source/ConstraintLayoutGuide.swift @@ -0,0 +1,36 @@ +// +// 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 + + +#if os(iOS) || os(tvOS) + @available(iOS 9.0, *) + public typealias ConstraintLayoutGuide = UILayoutGuide +#else + public class ConstraintLayoutGuide {} +#endif diff --git a/Source/UILayoutGuideDSL.swift b/Source/ConstraintLayoutGuideDSL.swift similarity index 89% rename from Source/UILayoutGuideDSL.swift rename to Source/ConstraintLayoutGuideDSL.swift index 588c5f1..62bd9b4 100644 --- a/Source/UILayoutGuideDSL.swift +++ b/Source/ConstraintLayoutGuideDSL.swift @@ -29,15 +29,15 @@ @available(iOS 9.0, *) -public struct UILayoutGuideDSL: ConstraintAttributesDSL { +public struct ConstraintLayoutGuideDSL: ConstraintAttributesDSL { public var target: AnyObject? { return self.guide } - internal let guide: UILayoutGuide + internal let guide: ConstraintLayoutGuide - internal init(guide: UILayoutGuide) { + internal init(guide: ConstraintLayoutGuide) { self.guide = guide } diff --git a/Source/ConstraintLayoutSupport.swift b/Source/ConstraintLayoutSupport.swift new file mode 100644 index 0000000..e92e9fb --- /dev/null +++ b/Source/ConstraintLayoutSupport.swift @@ -0,0 +1,36 @@ +// +// 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 + + +#if os(iOS) || os(tvOS) + @available(iOS 8.0, *) + public typealias ConstraintLayoutSupport = UILayoutSupport +#else + public class ConstraintLayoutSupport {} +#endif diff --git a/Source/UILayoutSupportDSL.swift b/Source/ConstraintLayoutSupportDSL.swift similarity index 91% rename from Source/UILayoutSupportDSL.swift rename to Source/ConstraintLayoutSupportDSL.swift index 0180d2f..5d6ae89 100644 --- a/Source/UILayoutSupportDSL.swift +++ b/Source/ConstraintLayoutSupportDSL.swift @@ -29,15 +29,15 @@ @available(iOS 8.0, *) -public struct UILayoutSupportDSL: ConstraintDSL { +public struct ConstraintLayoutSupportDSL: ConstraintDSL { public var target: AnyObject? { return self.support } - internal let support: UILayoutSupport + internal let support: ConstraintLayoutSupport - internal init(support: UILayoutSupport) { + internal init(support: ConstraintLayoutSupport) { self.support = support } diff --git a/Source/UILayoutGuide+Extensions.swift b/Source/UILayoutGuide+Extensions.swift index bd8c2a5..cd89d8a 100644 --- a/Source/UILayoutGuide+Extensions.swift +++ b/Source/UILayoutGuide+Extensions.swift @@ -27,10 +27,10 @@ @available(iOS 9.0, *) -public extension UILayoutGuide { +public extension ConstraintLayoutGuide { - public var snp: UILayoutGuideDSL { - return UILayoutGuideDSL(guide: self) + public var snp: ConstraintLayoutGuideDSL { + return ConstraintLayoutGuideDSL(guide: self) } } diff --git a/Source/UILayoutSupport+Extensions.swift b/Source/UILayoutSupport+Extensions.swift index eac30f7..cfbce2e 100644 --- a/Source/UILayoutSupport+Extensions.swift +++ b/Source/UILayoutSupport+Extensions.swift @@ -27,10 +27,10 @@ @available(iOS 8.0, *) -public extension UILayoutSupport { +public extension ConstraintLayoutSupport { - public var snp: UILayoutSupportDSL { - return UILayoutSupportDSL(support: self) + public var snp: ConstraintLayoutSupportDSL { + return ConstraintLayoutSupportDSL(support: self) } } diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 8b502b2..5c37c95 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -29,24 +29,6 @@ class SnapKitTests: XCTestCase { super.tearDown() } - func testLayoutGuideConstraints() { - #if os(iOS) || os(tvOS) - let vc = UIViewController() - vc.view = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) - - vc.view.addSubview(self.container) - - self.container.snp.makeConstraints { (make) -> Void in - 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 - } - func testMakeConstraints() { let v1 = View() let v2 = View() @@ -324,12 +306,12 @@ class SnapKitTests: XCTestCase { XCTAssertEqual(constraints[3].constant, -50, "Should be -50") } - func testUIEdgeInsetsAsImpliedEqualToConstraints() { + func testConstraintInsetsAsImpliedEqualToConstraints() { let view = View() self.container.addSubview(view) view.snp.makeConstraints { (make) -> Void in - make.edges.equalTo(UIEdgeInsets(top: 25, left: 25, bottom: 25, right: 25)) + make.edges.equalTo(ConstraintInsets(top: 25, left: 25, bottom: 25, right: 25)) } XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints") @@ -343,12 +325,12 @@ class SnapKitTests: XCTestCase { XCTAssertEqual(constraints[3].constant, -25, "Should be -25") } - func testUIEdgeInsetsAsConstraintsConstant() { + func testConstraintInsetsAsConstraintsConstant() { let view = View() self.container.addSubview(view) view.snp.makeConstraints { (make) -> Void in - make.edges.equalTo(self.container).inset(UIEdgeInsets(top: 25, left: 25, bottom: 25, right: 25)) + make.edges.equalTo(self.container).inset(ConstraintInsets(top: 25, left: 25, bottom: 25, right: 25)) } XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints") @@ -418,6 +400,7 @@ class SnapKitTests: XCTestCase { XCTAssertEqual(constraints[0].identifier, identifier, "Identifier should be 'Test'") } + #if os(iOS) || os(tvOS) func testEdgesToMargins() { var fromAttributes = Set() var toAttributes = Set() @@ -458,4 +441,21 @@ class SnapKitTests: XCTestCase { } + func testLayoutGuideConstraints() { + let vc = UIViewController() + vc.view = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) + + vc.view.addSubview(self.container) + + self.container.snp.makeConstraints { (make) -> Void in + 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 + } From ca34ad4252d542cfe0ba8840ef2c95737290e107 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Fri, 2 Sep 2016 01:39:43 +1200 Subject: [PATCH 49/58] Updated changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcbe628..0c56898 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ clean up the API. As such please use with caution and check your apps thoroughly * `.inset()` will no longer take `CGPoint` or `CGSize` as input * `.offset()` will no longer take `CGPoint`, `CGSize`, `EdgeInsets` as input * `updateConstraints` will no longer allow creating new constraints unless there are no existing constraints for the view. If it does generate new constraints it will throw a fatal error. +* `UIEdgeInsets` are now have their right and bottom value inverted for more natural results such as `make.edges.equalTo(UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)).inset()` ### Enhancements @@ -23,6 +24,7 @@ clean up the API. As such please use with caution and check your apps thoroughly * Added `var contentHuggingPriority: CGFloat` to `make` * Added `var contentCompressionResistancePriority: CGFloat` to `make` * Added support for `UILayoutGuide` via `make.left.equalTo(guide.snp.top)` +* Added support for constraining edges to margins or vice versa via `make.edges.equalTo(other.snp.margins)` # 0.21.0 - May 11 2016 From 2e4cebf41d8bd0833487381590ed90c38b9a2491 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Wed, 7 Sep 2016 20:23:54 +1200 Subject: [PATCH 50/58] =?UTF-8?q?Fix=20bug=20around=20view.snp.layoutConst?= =?UTF-8?q?raints=20being=20dealloc=E2=80=99d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Constraint.swift | 12 ++++++------ Source/ConstraintViewDSL.swift | 29 ++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index c6e5e01..2491c7b 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -46,7 +46,7 @@ public class Constraint { self.updateConstantAndPriorityIfNeeded() } } - private let layoutConstraints: NSHashTable + private var layoutConstraints: [LayoutConstraint] // MARK: Initialization @@ -66,7 +66,7 @@ public class Constraint { self.multiplier = multiplier self.constant = constant self.priority = priority - self.layoutConstraints = NSHashTable.weakObjects() + self.layoutConstraints = [] // get attributes let layoutFromAttributes = self.from.attributes.layoutAttributes @@ -157,7 +157,7 @@ public class Constraint { layoutConstraint.constraint = self // append - self.layoutConstraints.add(layoutConstraint) + self.layoutConstraints.append(layoutConstraint) } } @@ -213,7 +213,7 @@ public class Constraint { // MARK: Internal internal func updateConstantAndPriorityIfNeeded() { - for layoutConstraint in self.layoutConstraints.allObjects { + for layoutConstraint in self.layoutConstraints { let attribute = (layoutConstraint.secondAttribute == .notAnAttribute) ? layoutConstraint.firstAttribute : layoutConstraint.secondAttribute layoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: attribute) layoutConstraint.priority = self.priority.constraintPriorityTargetValue @@ -222,7 +222,7 @@ public class Constraint { internal func activateIfNeeded(updatingExisting: Bool = false) { let view = self.from.view! - let layoutConstraints = self.layoutConstraints.allObjects + let layoutConstraints = self.layoutConstraints let existingLayoutConstraints = view.snp.layoutConstraints if updatingExisting && existingLayoutConstraints.count > 0 { @@ -245,7 +245,7 @@ public class Constraint { internal func deactivateIfNeeded() { let view = self.from.view! - let layoutConstraints = self.layoutConstraints.allObjects + let layoutConstraints = self.layoutConstraints NSLayoutConstraint.deactivate(layoutConstraints) view.snp.remove(layoutConstraints: layoutConstraints) } diff --git a/Source/ConstraintViewDSL.swift b/Source/ConstraintViewDSL.swift index a782ea9..21e1ac8 100644 --- a/Source/ConstraintViewDSL.swift +++ b/Source/ConstraintViewDSL.swift @@ -101,17 +101,36 @@ public struct ConstraintViewDSL: ConstraintAttributesDSL { } internal var layoutConstraints: [LayoutConstraint] { - return objc_getAssociatedObject(self.view, &layoutConstraintsKey) as? [LayoutConstraint] ?? [] + return self.layoutConstraintsHashTable.allObjects } internal func add(layoutConstraints: [LayoutConstraint]) { - let merged = self.layoutConstraints + layoutConstraints - objc_setAssociatedObject(self.view, &layoutConstraintsKey, merged, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + let hashTable = self.layoutConstraintsHashTable + for layoutConstraint in layoutConstraints { + hashTable.add(layoutConstraint) + } + print(hashTable, self.layoutConstraintsHashTable) } internal func remove(layoutConstraints: [LayoutConstraint]) { - let merged = self.layoutConstraints.filter { !layoutConstraints.contains($0) } - objc_setAssociatedObject(self.view, &layoutConstraintsKey, merged, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + let hashTable = self.layoutConstraintsHashTable + for layoutConstraint in layoutConstraints { + hashTable.remove(layoutConstraint) + } + print(hashTable, self.layoutConstraintsHashTable) + } + + private var layoutConstraintsHashTable: NSHashTable { + let layoutConstraints: NSHashTable + + if let existing = objc_getAssociatedObject(self.view, &layoutConstraintsKey) as? NSHashTable { + layoutConstraints = existing + } else { + layoutConstraints = NSHashTable.weakObjects() + objc_setAssociatedObject(self.view, &layoutConstraintsKey, layoutConstraints, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + } + return layoutConstraints + } } From 9b1a0519eedf20526798cde6cd088b61496904e9 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 10 Sep 2016 16:31:28 +1200 Subject: [PATCH 51/58] Add back in equalToSuperview API --- Source/ConstraintMakerRelatable.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/ConstraintMakerRelatable.swift b/Source/ConstraintMakerRelatable.swift index 7a2968d..40a46fa 100644 --- a/Source/ConstraintMakerRelatable.swift +++ b/Source/ConstraintMakerRelatable.swift @@ -74,6 +74,14 @@ public class ConstraintMakerRelatable { return self.relatedTo(other, relation: .equal, file: file, line: line) } + @discardableResult + public func equalToSuperview(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { + guard let other = self.description.view.superview else { + fatalError("Expected superview but found nil when attempting make constraint `equalToSuperview`.") + } + return self.relatedTo(other, relation: .equal, file: file, line: line) + } + @discardableResult public func lessThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line) From cdedbcdea77fcfe46459cdba7019bfe7cb819821 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 10 Sep 2016 16:38:40 +1200 Subject: [PATCH 52/58] Fix bug where pinning composite to composite would fail --- Source/Constraint.swift | 6 +++--- Tests/Tests.swift | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 2491c7b..0bfce79 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -82,7 +82,7 @@ public class Constraint { // get layout to attribute let layoutToAttribute: NSLayoutAttribute #if os(iOS) || os(tvOS) - if layoutToAttributes.count > 1 { + if layoutToAttributes.count > 0 { if self.from.attributes == .edges && self.to.attributes == .margins { switch layoutFromAttribute { case .left: @@ -109,11 +109,11 @@ public class Constraint { default: fatalError() } + } else if self.from.attributes == self.to.attributes { + layoutToAttribute = layoutFromAttribute } else { layoutToAttribute = layoutToAttributes[0] } - } else if layoutToAttributes.count == 1 { - layoutToAttribute = layoutToAttributes[0] } else { layoutToAttribute = layoutFromAttribute } diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 5c37c95..1896d8d 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -441,6 +441,28 @@ class SnapKitTests: XCTestCase { } + func testEdgesToEdges() { + var fromAttributes = Set() + var toAttributes = Set() + + let view = View() + self.container.addSubview(view) + + view.snp.remakeConstraints { (make) -> Void in + make.edges.equalTo(self.container.snp.edges) + } + + XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints") + + for constraint in (container.snp_constraints as! [NSLayoutConstraint]) { + fromAttributes.insert(constraint.firstAttribute) + toAttributes.insert(constraint.secondAttribute) + } + + XCTAssert(fromAttributes == [.top, .left, .bottom, .right]) + XCTAssert(toAttributes == [.top, .left, .bottom, .right]) + } + func testLayoutGuideConstraints() { let vc = UIViewController() vc.view = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) From ac0b5829aa546985c0a3cd106b7e4177e1d963af Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 10 Sep 2016 16:40:55 +1200 Subject: [PATCH 53/58] Remove prints --- Source/ConstraintViewDSL.swift | 2 -- Tests/Tests.swift | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/ConstraintViewDSL.swift b/Source/ConstraintViewDSL.swift index 21e1ac8..55bb845 100644 --- a/Source/ConstraintViewDSL.swift +++ b/Source/ConstraintViewDSL.swift @@ -109,7 +109,6 @@ public struct ConstraintViewDSL: ConstraintAttributesDSL { for layoutConstraint in layoutConstraints { hashTable.add(layoutConstraint) } - print(hashTable, self.layoutConstraintsHashTable) } internal func remove(layoutConstraints: [LayoutConstraint]) { @@ -117,7 +116,6 @@ public struct ConstraintViewDSL: ConstraintAttributesDSL { for layoutConstraint in layoutConstraints { hashTable.remove(layoutConstraint) } - print(hashTable, self.layoutConstraintsHashTable) } private var layoutConstraintsHashTable: NSHashTable { diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 1896d8d..8b1c83c 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -473,9 +473,7 @@ class SnapKitTests: XCTestCase { 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 From 67271dc6667fae9633649422bc608ec731900a7f Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 10 Sep 2016 21:51:20 +1200 Subject: [PATCH 54/58] Rework how updateConstraints works if no existing constraints updateConstraints will no longer allow creation of new constraints but if you call updateConstraints and there have been no previous constraints created it will re-route to makeConstraints --- Source/Constraint.swift | 4 +--- Source/ConstraintMaker.swift | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 0bfce79..9928cde 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -225,8 +225,7 @@ public class Constraint { let layoutConstraints = self.layoutConstraints let existingLayoutConstraints = view.snp.layoutConstraints - if updatingExisting && existingLayoutConstraints.count > 0 { - + if updatingExisting { for layoutConstraint in layoutConstraints { let existingLayoutConstraint = existingLayoutConstraints.first { $0 == layoutConstraint } guard let updateLayoutConstraint = existingLayoutConstraint else { @@ -236,7 +235,6 @@ public class Constraint { let updateLayoutAttribute = (updateLayoutConstraint.secondAttribute == .notAnAttribute) ? updateLayoutConstraint.firstAttribute : updateLayoutConstraint.secondAttribute updateLayoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: updateLayoutAttribute) } - } else { NSLayoutConstraint.activate(layoutConstraints) view.snp.add(layoutConstraints: layoutConstraints) diff --git a/Source/ConstraintMaker.swift b/Source/ConstraintMaker.swift index 0749104..0ea2dd2 100644 --- a/Source/ConstraintMaker.swift +++ b/Source/ConstraintMaker.swift @@ -180,6 +180,11 @@ public class ConstraintMaker { } internal static func updateConstraints(view: ConstraintView, closure: (_ make: ConstraintMaker) -> Void) { + guard view.snp.layoutConstraints.count > 0 else { + self.makeConstraints(view: view, closure: closure) + return + } + let maker = ConstraintMaker(view: view) closure(maker) let constraints = maker.descriptions From 5ee6f49788da97d487042c1ac49f2d6b1a865cec Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Tue, 13 Sep 2016 22:33:43 +1200 Subject: [PATCH 55/58] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c56898..2cc17e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ clean up the API. As such please use with caution and check your apps thoroughly ### Breaking * iOS 7.0 support has been removed +* `install` and `uninstall` have been removed, use `activate` and `deactivate` instead * DSL is now accessed through `.snp.*` rather than `.snp_*`. For example `view.snp.makeConstraints { }` * Constraints are now updated through `update(offset:)`, `update(inset:)` and `update(priority:)` * `.inset()` will no longer take `CGPoint` or `CGSize` as input @@ -82,4 +83,4 @@ clean up the API. As such please use with caution and check your apps thoroughly * Re-worked some internal API to allow for future updates * Added `snp_prepareConstraints -> [Constraint]` which allows pre-building of constraints -* Added a fatal error to `and` when it is used after relation has been set \ No newline at end of file +* Added a fatal error to `and` when it is used after relation has been set From fa5290e5ff94bb2fe8393ef2f27b58cf7b2302ff Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Wed, 14 Sep 2016 20:44:06 +1200 Subject: [PATCH 56/58] Improve project setup for multiplatform --- .travis.yml | 19 +- SnapKit.xcodeproj/project.pbxproj | 597 +----------------- .../xcschemes/SnapKit OSX.xcscheme | 114 ---- .../xcschemes/SnapKit Tests.xcscheme | 56 ++ .../xcschemes/SnapKit iOS.xcscheme | 114 ---- ...SnapKit tvOS.xcscheme => SnapKit.xcscheme} | 34 +- 6 files changed, 89 insertions(+), 845 deletions(-) delete mode 100644 SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme create mode 100644 SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit Tests.xcscheme delete mode 100644 SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme rename SnapKit.xcodeproj/xcshareddata/xcschemes/{SnapKit tvOS.xcscheme => SnapKit.xcscheme} (67%) diff --git a/.travis.yml b/.travis.yml index 8565bda..294eb13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,10 @@ language: objective-c -osx_image: xcode7 -branches: - only: - - master - - develop +osx_image: xcode8 + env: - - LC_CTYPE=en_US.UTF-8 LANG=en_US.UTF-8 -before_install: - - gem install xcpretty -N + - ACTION=test PLATFORM=Mac DESTINATION='platform=OS X' + - ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' + - ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' + script: - - set -o pipefail - - xcodebuild -project SnapKit.xcodeproj -scheme "SnapKit iOS" -sdk iphonesimulator - -destination "platform=iOS Simulator,name=iPhone 6" ONLY_ACTIVE_ARCH=NO test | xcpretty -c - - pod lib lint --quick + - set -o pipefail && xcodebuild -scheme SnapKit -destination "$DESTINATION" $ACTION | xcpretty diff --git a/SnapKit.xcodeproj/project.pbxproj b/SnapKit.xcodeproj/project.pbxproj index 6aadaca..6b57049 100644 --- a/SnapKit.xcodeproj/project.pbxproj +++ b/SnapKit.xcodeproj/project.pbxproj @@ -7,127 +7,45 @@ objects = { /* Begin PBXBuildFile section */ - 537DCE9B1C35CD4100B5B899 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 537DCE9A1C35CD4100B5B899 /* UIKit.framework */; }; - 537DCEA01C35CDF800B5B899 /* SnapKit.h in Headers */ = {isa = PBXBuildFile; fileRef = EECDB3661AC0C95C006BBC11 /* SnapKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 537DCEB41C35D90A00B5B899 /* SnapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 537DCE921C35CC8800B5B899 /* SnapKit.framework */; }; - 537DCEBA1C35DA9700B5B899 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB36A1AC0C95C006BBC11 /* Tests.swift */; }; EE235F5F1C5785BC00C08960 /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F5E1C5785BC00C08960 /* Debugging.swift */; }; - EE235F601C5785BC00C08960 /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F5E1C5785BC00C08960 /* Debugging.swift */; }; - EE235F611C5785BC00C08960 /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F5E1C5785BC00C08960 /* Debugging.swift */; }; EE235F6D1C5785C600C08960 /* Constraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F621C5785C600C08960 /* Constraint.swift */; }; - EE235F6E1C5785C600C08960 /* Constraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F621C5785C600C08960 /* Constraint.swift */; }; - EE235F6F1C5785C600C08960 /* Constraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F621C5785C600C08960 /* Constraint.swift */; }; EE235F701C5785C600C08960 /* ConstraintDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F631C5785C600C08960 /* ConstraintDescription.swift */; }; - EE235F711C5785C600C08960 /* ConstraintDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F631C5785C600C08960 /* ConstraintDescription.swift */; }; - EE235F721C5785C600C08960 /* ConstraintDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F631C5785C600C08960 /* ConstraintDescription.swift */; }; EE235F731C5785C600C08960 /* ConstraintInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F641C5785C600C08960 /* ConstraintInsets.swift */; }; - EE235F741C5785C600C08960 /* ConstraintInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F641C5785C600C08960 /* ConstraintInsets.swift */; }; - EE235F751C5785C600C08960 /* ConstraintInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F641C5785C600C08960 /* ConstraintInsets.swift */; }; EE235F761C5785C600C08960 /* ConstraintConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F651C5785C600C08960 /* ConstraintConfig.swift */; }; - EE235F771C5785C600C08960 /* ConstraintConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F651C5785C600C08960 /* ConstraintConfig.swift */; }; - EE235F781C5785C600C08960 /* ConstraintConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F651C5785C600C08960 /* ConstraintConfig.swift */; }; 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 */; }; 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 */; }; 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 */; }; EE235F881C5785C600C08960 /* ConstraintItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6B1C5785C600C08960 /* ConstraintItem.swift */; }; - EE235F891C5785C600C08960 /* ConstraintItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6B1C5785C600C08960 /* ConstraintItem.swift */; }; - EE235F8A1C5785C600C08960 /* ConstraintItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6B1C5785C600C08960 /* ConstraintItem.swift */; }; EE235F8B1C5785C600C08960 /* LayoutConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6C1C5785C600C08960 /* LayoutConstraint.swift */; }; - EE235F8C1C5785C600C08960 /* LayoutConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6C1C5785C600C08960 /* LayoutConstraint.swift */; }; - EE235F8D1C5785C600C08960 /* LayoutConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F6C1C5785C600C08960 /* LayoutConstraint.swift */; }; EE235F941C5785CE00C08960 /* ConstraintRelatableTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F8E1C5785CE00C08960 /* ConstraintRelatableTarget.swift */; }; - EE235F951C5785CE00C08960 /* ConstraintRelatableTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F8E1C5785CE00C08960 /* ConstraintRelatableTarget.swift */; }; - EE235F961C5785CE00C08960 /* ConstraintRelatableTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F8E1C5785CE00C08960 /* ConstraintRelatableTarget.swift */; }; EE235F971C5785CE00C08960 /* ConstraintConstantTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F8F1C5785CE00C08960 /* ConstraintConstantTarget.swift */; }; - EE235F981C5785CE00C08960 /* ConstraintConstantTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F8F1C5785CE00C08960 /* ConstraintConstantTarget.swift */; }; - EE235F991C5785CE00C08960 /* ConstraintConstantTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F8F1C5785CE00C08960 /* ConstraintConstantTarget.swift */; }; EE235F9A1C5785CE00C08960 /* ConstraintPriorityTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F901C5785CE00C08960 /* ConstraintPriorityTarget.swift */; }; - EE235F9B1C5785CE00C08960 /* ConstraintPriorityTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F901C5785CE00C08960 /* ConstraintPriorityTarget.swift */; }; - EE235F9C1C5785CE00C08960 /* ConstraintPriorityTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F901C5785CE00C08960 /* ConstraintPriorityTarget.swift */; }; EE235F9D1C5785CE00C08960 /* ConstraintMultiplierTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F911C5785CE00C08960 /* ConstraintMultiplierTarget.swift */; }; - EE235F9E1C5785CE00C08960 /* ConstraintMultiplierTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F911C5785CE00C08960 /* ConstraintMultiplierTarget.swift */; }; - EE235F9F1C5785CE00C08960 /* ConstraintMultiplierTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F911C5785CE00C08960 /* ConstraintMultiplierTarget.swift */; }; EE235FA01C5785CE00C08960 /* ConstraintOffsetTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F921C5785CE00C08960 /* ConstraintOffsetTarget.swift */; }; - EE235FA11C5785CE00C08960 /* ConstraintOffsetTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F921C5785CE00C08960 /* ConstraintOffsetTarget.swift */; }; - EE235FA21C5785CE00C08960 /* ConstraintOffsetTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F921C5785CE00C08960 /* ConstraintOffsetTarget.swift */; }; EE235FA31C5785CE00C08960 /* ConstraintInsetTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F931C5785CE00C08960 /* ConstraintInsetTarget.swift */; }; - EE235FA41C5785CE00C08960 /* ConstraintInsetTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F931C5785CE00C08960 /* ConstraintInsetTarget.swift */; }; - EE235FA51C5785CE00C08960 /* ConstraintInsetTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F931C5785CE00C08960 /* ConstraintInsetTarget.swift */; }; EE235FAC1C5785D400C08960 /* ConstraintMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA61C5785D400C08960 /* ConstraintMaker.swift */; }; - EE235FAD1C5785D400C08960 /* ConstraintMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA61C5785D400C08960 /* ConstraintMaker.swift */; }; - EE235FAE1C5785D400C08960 /* ConstraintMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA61C5785D400C08960 /* ConstraintMaker.swift */; }; EE235FAF1C5785D400C08960 /* ConstraintMakerFinalizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA71C5785D400C08960 /* ConstraintMakerFinalizable.swift */; }; - EE235FB01C5785D400C08960 /* ConstraintMakerFinalizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA71C5785D400C08960 /* ConstraintMakerFinalizable.swift */; }; - EE235FB11C5785D400C08960 /* ConstraintMakerFinalizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA71C5785D400C08960 /* ConstraintMakerFinalizable.swift */; }; EE235FB21C5785D400C08960 /* ConstraintMakerPriortizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA81C5785D400C08960 /* ConstraintMakerPriortizable.swift */; }; - EE235FB31C5785D400C08960 /* ConstraintMakerPriortizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA81C5785D400C08960 /* ConstraintMakerPriortizable.swift */; }; - EE235FB41C5785D400C08960 /* ConstraintMakerPriortizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA81C5785D400C08960 /* ConstraintMakerPriortizable.swift */; }; EE235FB51C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA91C5785D400C08960 /* ConstraintMakerEditable.swift */; }; - EE235FB61C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA91C5785D400C08960 /* ConstraintMakerEditable.swift */; }; - EE235FB71C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FA91C5785D400C08960 /* ConstraintMakerEditable.swift */; }; EE235FB81C5785D400C08960 /* ConstraintMakerRelatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FAA1C5785D400C08960 /* ConstraintMakerRelatable.swift */; }; - EE235FB91C5785D400C08960 /* ConstraintMakerRelatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FAA1C5785D400C08960 /* ConstraintMakerRelatable.swift */; }; - EE235FBA1C5785D400C08960 /* ConstraintMakerRelatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FAA1C5785D400C08960 /* ConstraintMakerRelatable.swift */; }; EE235FBB1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FAB1C5785D400C08960 /* ConstraintMakerExtendable.swift */; }; - EE235FBC1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FAB1C5785D400C08960 /* ConstraintMakerExtendable.swift */; }; - EE235FBD1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FAB1C5785D400C08960 /* ConstraintMakerExtendable.swift */; }; 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 /* ConstraintLayoutSupportDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift */; }; - EE235FC41C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift */; }; - EE235FC51C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* ConstraintLayoutSupportDSL.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 */; }; 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 */; }; - EE94F6111AC0F146008767FF /* SnapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EECDB37A1AC0C9D4006BBC11 /* SnapKit.framework */; }; EECDB3741AC0C9B6006BBC11 /* SnapKit.h in Headers */ = {isa = PBXBuildFile; fileRef = EECDB3661AC0C95C006BBC11 /* SnapKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 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 /* ConstraintLayoutGuideDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68F9D1D78492400980C26 /* ConstraintLayoutGuideDSL.swift */; }; EEF68FA61D784A5300980C26 /* ConstraintDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FA51D784A5300980C26 /* ConstraintDSL.swift */; }; - EEF68FAB1D784E3800980C26 /* ConstraintLayoutGuideDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68F9D1D78492400980C26 /* ConstraintLayoutGuideDSL.swift */; }; - EEF68FAC1D784E3800980C26 /* ConstraintLayoutGuideDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68F9D1D78492400980C26 /* ConstraintLayoutGuideDSL.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 */; }; EEF68FBC1D78653000980C26 /* ConstraintLayoutGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FBB1D78653000980C26 /* ConstraintLayoutGuide.swift */; }; - EEF68FBD1D78653000980C26 /* ConstraintLayoutGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FBB1D78653000980C26 /* ConstraintLayoutGuide.swift */; }; - EEF68FBE1D78653000980C26 /* ConstraintLayoutGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FBB1D78653000980C26 /* ConstraintLayoutGuide.swift */; }; EEF68FC01D7865AA00980C26 /* ConstraintLayoutSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FBF1D7865AA00980C26 /* ConstraintLayoutSupport.swift */; }; - EEF68FC11D7865AA00980C26 /* ConstraintLayoutSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FBF1D7865AA00980C26 /* ConstraintLayoutSupport.swift */; }; - EEF68FC21D7865AA00980C26 /* ConstraintLayoutSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68FBF1D7865AA00980C26 /* ConstraintLayoutSupport.swift */; }; /* End PBXBuildFile section */ -/* Begin PBXContainerItemProxy section */ - EECDB3861AC0C9D4006BBC11 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = DDC9FD8D1981B4DD009612C7 /* Project object */; - proxyType = 1; - remoteGlobalIDString = EECDB3791AC0C9D4006BBC11; - remoteInfo = "SnapKit OSX"; - }; -/* End PBXContainerItemProxy section */ - /* Begin PBXFileReference section */ - 537DCE921C35CC8800B5B899 /* SnapKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SnapKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 537DCE9A1C35CD4100B5B899 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.1.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; - 537DCEAF1C35D90A00B5B899 /* SnapKit tvOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SnapKit tvOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; EE235F5E1C5785BC00C08960 /* Debugging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Debugging.swift; sourceTree = ""; }; EE235F621C5785C600C08960 /* Constraint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constraint.swift; sourceTree = ""; }; EE235F631C5785C600C08960 /* ConstraintDescription.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintDescription.swift; sourceTree = ""; }; @@ -156,13 +74,11 @@ 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; }; - EEBCC9E219CC627E0083B827 /* SnapKit iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SnapKit iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + EEBCC9E219CC627E0083B827 /* SnapKit Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SnapKit Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; EECDB3641AC0C95C006BBC11 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; EECDB3661AC0C95C006BBC11 /* SnapKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SnapKit.h; sourceTree = ""; }; EECDB3691AC0C95C006BBC11 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 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 /* ConstraintLayoutGuideDSL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintLayoutGuideDSL.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 = ""; }; @@ -172,30 +88,6 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ - 537DCE8E1C35CC8800B5B899 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 537DCE9B1C35CD4100B5B899 /* UIKit.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 537DCEAC1C35D90A00B5B899 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 537DCEB41C35D90A00B5B899 /* SnapKit.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - EE94F60D1AC0F132008767FF /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - EE94F6111AC0F146008767FF /* SnapKit.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; EE94F60E1AC0F136008767FF /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -212,14 +104,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - EECDB3761AC0C9D4006BBC11 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - EE94F60B1AC0F10F008767FF /* AppKit.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -236,11 +120,7 @@ isa = PBXGroup; children = ( EEBCC9D819CC627D0083B827 /* SnapKit.framework */, - EEBCC9E219CC627E0083B827 /* SnapKit iOS Tests.xctest */, - EECDB37A1AC0C9D4006BBC11 /* SnapKit.framework */, - EECDB3841AC0C9D4006BBC11 /* SnapKit OSX Tests.xctest */, - 537DCE921C35CC8800B5B899 /* SnapKit.framework */, - 537DCEAF1C35D90A00B5B899 /* SnapKit tvOS Tests.xctest */, + EEBCC9E219CC627E0083B827 /* SnapKit Tests.xctest */, ); name = Products; sourceTree = ""; @@ -365,14 +245,6 @@ /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ - 537DCE8F1C35CC8800B5B899 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 537DCEA01C35CDF800B5B899 /* SnapKit.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; EEBCC9D519CC627D0083B827 /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; @@ -381,55 +253,12 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - EECDB3771AC0C9D4006BBC11 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - EECDB39D1AC0CC03006BBC11 /* SnapKit.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ - 537DCE911C35CC8800B5B899 /* SnapKit tvOS */ = { + EEBCC9D719CC627D0083B827 /* SnapKit */ = { isa = PBXNativeTarget; - buildConfigurationList = 537DCE991C35CC8800B5B899 /* Build configuration list for PBXNativeTarget "SnapKit tvOS" */; - buildPhases = ( - 537DCE8D1C35CC8800B5B899 /* Sources */, - 537DCE8E1C35CC8800B5B899 /* Frameworks */, - 537DCE8F1C35CC8800B5B899 /* Headers */, - 537DCE901C35CC8800B5B899 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "SnapKit tvOS"; - productName = "SnapKit tvOS"; - productReference = 537DCE921C35CC8800B5B899 /* SnapKit.framework */; - productType = "com.apple.product-type.framework"; - }; - 537DCEAE1C35D90A00B5B899 /* SnapKit tvOS Tests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 537DCEB91C35D90A00B5B899 /* Build configuration list for PBXNativeTarget "SnapKit tvOS Tests" */; - buildPhases = ( - 537DCEAB1C35D90A00B5B899 /* Sources */, - 537DCEAC1C35D90A00B5B899 /* Frameworks */, - 537DCEAD1C35D90A00B5B899 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "SnapKit tvOS Tests"; - productName = "SnapKit tvOS Tests"; - productReference = 537DCEAF1C35D90A00B5B899 /* SnapKit tvOS Tests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; - EEBCC9D719CC627D0083B827 /* SnapKit iOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = EEBCC9E819CC627E0083B827 /* Build configuration list for PBXNativeTarget "SnapKit iOS" */; + buildConfigurationList = EEBCC9E819CC627E0083B827 /* Build configuration list for PBXNativeTarget "SnapKit" */; buildPhases = ( EEBCC9D319CC627D0083B827 /* Sources */, EEBCC9D419CC627D0083B827 /* Frameworks */, @@ -440,14 +269,14 @@ ); dependencies = ( ); - name = "SnapKit iOS"; + name = SnapKit; productName = SnapKit; productReference = EEBCC9D819CC627D0083B827 /* SnapKit.framework */; productType = "com.apple.product-type.framework"; }; - EEBCC9E119CC627D0083B827 /* SnapKit iOS Tests */ = { + EEBCC9E119CC627D0083B827 /* SnapKit Tests */ = { isa = PBXNativeTarget; - buildConfigurationList = EEBCC9EB19CC627E0083B827 /* Build configuration list for PBXNativeTarget "SnapKit iOS Tests" */; + buildConfigurationList = EEBCC9EB19CC627E0083B827 /* Build configuration list for PBXNativeTarget "SnapKit Tests" */; buildPhases = ( EEBCC9DE19CC627D0083B827 /* Sources */, EE94F60E1AC0F136008767FF /* Frameworks */, @@ -457,45 +286,9 @@ ); dependencies = ( ); - name = "SnapKit iOS Tests"; + name = "SnapKit Tests"; productName = SnapKitTests; - productReference = EEBCC9E219CC627E0083B827 /* SnapKit iOS Tests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; - EECDB3791AC0C9D4006BBC11 /* SnapKit OSX */ = { - isa = PBXNativeTarget; - buildConfigurationList = EECDB38D1AC0C9D4006BBC11 /* Build configuration list for PBXNativeTarget "SnapKit OSX" */; - buildPhases = ( - EECDB3751AC0C9D4006BBC11 /* Sources */, - EECDB3761AC0C9D4006BBC11 /* Frameworks */, - EECDB3771AC0C9D4006BBC11 /* Headers */, - EECDB3781AC0C9D4006BBC11 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "SnapKit OSX"; - productName = "SnapKit OSX"; - productReference = EECDB37A1AC0C9D4006BBC11 /* SnapKit.framework */; - productType = "com.apple.product-type.framework"; - }; - EECDB3831AC0C9D4006BBC11 /* SnapKit OSX Tests */ = { - isa = PBXNativeTarget; - buildConfigurationList = EECDB3901AC0C9D4006BBC11 /* Build configuration list for PBXNativeTarget "SnapKit OSX Tests" */; - buildPhases = ( - EECDB3801AC0C9D4006BBC11 /* Sources */, - EE94F60D1AC0F132008767FF /* Frameworks */, - EECDB3821AC0C9D4006BBC11 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - EECDB3871AC0C9D4006BBC11 /* PBXTargetDependency */, - ); - name = "SnapKit OSX Tests"; - productName = "SnapKit OSXTests"; - productReference = EECDB3841AC0C9D4006BBC11 /* SnapKit OSX Tests.xctest */; + productReference = EEBCC9E219CC627E0083B827 /* SnapKit Tests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; /* End PBXNativeTarget section */ @@ -508,13 +301,6 @@ LastUpgradeCheck = 0800; ORGANIZATIONNAME = "SnapKit Team"; TargetAttributes = { - 537DCE911C35CC8800B5B899 = { - CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0800; - }; - 537DCEAE1C35D90A00B5B899 = { - CreatedOnToolsVersion = 7.2; - }; EEBCC9D719CC627D0083B827 = { CreatedOnToolsVersion = 6.0; LastSwiftMigration = 0800; @@ -524,12 +310,6 @@ LastSwiftMigration = 0800; ProvisioningStyle = Automatic; }; - EECDB3791AC0C9D4006BBC11 = { - CreatedOnToolsVersion = 6.2; - }; - EECDB3831AC0C9D4006BBC11 = { - CreatedOnToolsVersion = 6.2; - }; }; }; buildConfigurationList = DDC9FD901981B4DD009612C7 /* Build configuration list for PBXProject "SnapKit" */; @@ -545,31 +325,13 @@ projectDirPath = ""; projectRoot = ""; targets = ( - EEBCC9D719CC627D0083B827 /* SnapKit iOS */, - 537DCE911C35CC8800B5B899 /* SnapKit tvOS */, - EECDB3791AC0C9D4006BBC11 /* SnapKit OSX */, - EEBCC9E119CC627D0083B827 /* SnapKit iOS Tests */, - 537DCEAE1C35D90A00B5B899 /* SnapKit tvOS Tests */, - EECDB3831AC0C9D4006BBC11 /* SnapKit OSX Tests */, + EEBCC9D719CC627D0083B827 /* SnapKit */, + EEBCC9E119CC627D0083B827 /* SnapKit Tests */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ - 537DCE901C35CC8800B5B899 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 537DCEAD1C35D90A00B5B899 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; EEBCC9D619CC627D0083B827 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -584,69 +346,9 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - EECDB3781AC0C9D4006BBC11 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - EECDB3821AC0C9D4006BBC11 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ - 537DCE8D1C35CC8800B5B899 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - EE235F741C5785C600C08960 /* ConstraintInsets.swift in Sources */, - EE235FB01C5785D400C08960 /* ConstraintMakerFinalizable.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 /* ConstraintLayoutGuideDSL.swift in Sources */, - EE235FB61C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */, - EEF68FBD1D78653000980C26 /* ConstraintLayoutGuide.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 */, - EEF68FC11D7865AA00980C26 /* ConstraintLayoutSupport.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 */, - 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 /* ConstraintLayoutSupportDSL.swift in Sources */, - EE235F801C5785C600C08960 /* ConstraintRelation.swift in Sources */, - EEF68FB51D784FBA00980C26 /* UILayoutSupport+Extensions.swift in Sources */, - EE235F711C5785C600C08960 /* ConstraintDescription.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 537DCEAB1C35D90A00B5B899 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 537DCEBA1C35DA9700B5B899 /* Tests.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; EEBCC9D319CC627D0083B827 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -693,148 +395,9 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - EECDB3751AC0C9D4006BBC11 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - EE235F751C5785C600C08960 /* ConstraintInsets.swift in Sources */, - EE235FB11C5785D400C08960 /* ConstraintMakerFinalizable.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 /* ConstraintLayoutGuideDSL.swift in Sources */, - EE235FB71C5785D400C08960 /* ConstraintMakerEditable.swift in Sources */, - EEF68FBE1D78653000980C26 /* ConstraintLayoutGuide.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 */, - EEF68FC21D7865AA00980C26 /* ConstraintLayoutSupport.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 */, - 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 /* ConstraintLayoutSupportDSL.swift in Sources */, - EE235F811C5785C600C08960 /* ConstraintRelation.swift in Sources */, - EEF68FB61D784FBA00980C26 /* UILayoutSupport+Extensions.swift in Sources */, - EE235F721C5785C600C08960 /* ConstraintDescription.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - EECDB3801AC0C9D4006BBC11 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - EECDB3941AC0CB52006BBC11 /* Tests.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXTargetDependency section */ - EECDB3871AC0C9D4006BBC11 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = EECDB3791AC0C9D4006BBC11 /* SnapKit OSX */; - targetProxy = EECDB3861AC0C9D4006BBC11 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - /* Begin XCBuildConfiguration section */ - 537DCE971C35CC8800B5B899 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = dwarf; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = io.snapkit.SnapKit; - PRODUCT_NAME = SnapKit; - SDKROOT = appletvos; - SKIP_INSTALL = YES; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; - TARGETED_DEVICE_FAMILY = 3; - TVOS_DEPLOYMENT_TARGET = 9.0; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Debug; - }; - 537DCE981C35CC8800B5B899 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_MODULES = YES; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = io.snapkit.SnapKit; - PRODUCT_NAME = SnapKit; - SDKROOT = appletvos; - SKIP_INSTALL = YES; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; - TARGETED_DEVICE_FAMILY = 3; - TVOS_DEPLOYMENT_TARGET = 9.0; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Release; - }; - 537DCEB71C35D90A00B5B899 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - DEBUG_INFORMATION_FORMAT = dwarf; - GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = appletvos; - TVOS_DEPLOYMENT_TARGET = 9.1; - }; - name = Debug; - }; - 537DCEB81C35D90A00B5B899 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = appletvos; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - TVOS_DEPLOYMENT_TARGET = 9.1; - }; - name = Release; - }; DDC9FDAF1981B4DD009612C7 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -876,9 +439,10 @@ MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvsimulator appletvos macosx"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 3.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = "1,2,3,4"; }; name = Debug; }; @@ -915,8 +479,9 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvsimulator appletvos macosx"; SWIFT_VERSION = 3.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = "1,2,3,4"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -937,7 +502,6 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SnapKit; SKIP_INSTALL = YES; - SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -960,7 +524,6 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SnapKit; SKIP_INSTALL = YES; - SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -973,7 +536,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks @loader_path/../Frameworks @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 3.0; @@ -986,7 +549,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks @loader_path/../Frameworks @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; @@ -994,113 +557,9 @@ }; name = Release; }; - EECDB38E1AC0C9D4006BBC11 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_MODULES = YES; - COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_VERSION = A; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = SnapKit; - SDKROOT = macosx; - SKIP_INSTALL = YES; - SUPPORTED_PLATFORMS = macosx; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Debug; - }; - EECDB38F1AC0C9D4006BBC11 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_MODULES = YES; - COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_VERSION = A; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = SnapKit; - SDKROOT = macosx; - SKIP_INSTALL = YES; - SUPPORTED_PLATFORMS = macosx; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Release; - }; - EECDB3911AC0C9D4006BBC11 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - FRAMEWORK_SEARCH_PATHS = "$(inherited)"; - INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.10; - PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Debug; - }; - EECDB3921AC0C9D4006BBC11 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - FRAMEWORK_SEARCH_PATHS = "$(inherited)"; - INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.10; - PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - }; - name = Release; - }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 537DCE991C35CC8800B5B899 /* Build configuration list for PBXNativeTarget "SnapKit tvOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 537DCE971C35CC8800B5B899 /* Debug */, - 537DCE981C35CC8800B5B899 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 537DCEB91C35D90A00B5B899 /* Build configuration list for PBXNativeTarget "SnapKit tvOS Tests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 537DCEB71C35D90A00B5B899 /* Debug */, - 537DCEB81C35D90A00B5B899 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; DDC9FD901981B4DD009612C7 /* Build configuration list for PBXProject "SnapKit" */ = { isa = XCConfigurationList; buildConfigurations = ( @@ -1110,7 +569,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - EEBCC9E819CC627E0083B827 /* Build configuration list for PBXNativeTarget "SnapKit iOS" */ = { + EEBCC9E819CC627E0083B827 /* Build configuration list for PBXNativeTarget "SnapKit" */ = { isa = XCConfigurationList; buildConfigurations = ( EEBCC9E919CC627E0083B827 /* Debug */, @@ -1119,7 +578,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - EEBCC9EB19CC627E0083B827 /* Build configuration list for PBXNativeTarget "SnapKit iOS Tests" */ = { + EEBCC9EB19CC627E0083B827 /* Build configuration list for PBXNativeTarget "SnapKit Tests" */ = { isa = XCConfigurationList; buildConfigurations = ( EEBCC9EC19CC627E0083B827 /* Debug */, @@ -1128,24 +587,6 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - EECDB38D1AC0C9D4006BBC11 /* Build configuration list for PBXNativeTarget "SnapKit OSX" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - EECDB38E1AC0C9D4006BBC11 /* Debug */, - EECDB38F1AC0C9D4006BBC11 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - EECDB3901AC0C9D4006BBC11 /* Build configuration list for PBXNativeTarget "SnapKit OSX Tests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - EECDB3911AC0C9D4006BBC11 /* Debug */, - EECDB3921AC0C9D4006BBC11 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; /* End XCConfigurationList section */ }; rootObject = DDC9FD8D1981B4DD009612C7 /* Project object */; diff --git a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme deleted file mode 100644 index 410e5f9..0000000 --- a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit OSX.xcscheme +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit Tests.xcscheme b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit Tests.xcscheme new file mode 100644 index 0000000..67d5136 --- /dev/null +++ b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit Tests.xcscheme @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme deleted file mode 100644 index 9dc5b70..0000000 --- a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit iOS.xcscheme +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit tvOS.xcscheme b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit.xcscheme similarity index 67% rename from SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit tvOS.xcscheme rename to SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit.xcscheme index 3c476cc..367c4d8 100644 --- a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit tvOS.xcscheme +++ b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit.xcscheme @@ -14,9 +14,9 @@ buildForAnalyzing = "YES"> @@ -26,29 +26,9 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES" - codeCoverageEnabled = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES"> - - - - - - - - @@ -65,9 +45,9 @@ @@ -83,9 +63,9 @@ From fa96e379bc7880f1f60eba48430763c490a7696b Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Wed, 14 Sep 2016 20:45:03 +1200 Subject: [PATCH 57/58] Add tests to updated build scheme --- .../xcshareddata/xcschemes/SnapKit.xcscheme | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit.xcscheme b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit.xcscheme index 367c4d8..0e9a1a7 100644 --- a/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit.xcscheme +++ b/SnapKit.xcodeproj/xcshareddata/xcschemes/SnapKit.xcscheme @@ -28,7 +28,26 @@ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "YES"> + + + + + + + + From 25bd7dab9e0a2aec5c7867b1fc9135857425ad84 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Wed, 14 Sep 2016 20:49:36 +1200 Subject: [PATCH 58/58] Fix for tests --- SnapKit.xcodeproj/project.pbxproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/SnapKit.xcodeproj/project.pbxproj b/SnapKit.xcodeproj/project.pbxproj index 6b57049..e7480f6 100644 --- a/SnapKit.xcodeproj/project.pbxproj +++ b/SnapKit.xcodeproj/project.pbxproj @@ -33,7 +33,6 @@ EE235FC31C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FBF1C5785DC00C08960 /* ConstraintLayoutSupportDSL.swift */; }; EE235FC81C5785E200C08960 /* ConstraintView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235FC61C5785E200C08960 /* ConstraintView+Extensions.swift */; }; EE4910991B19A40200A54F1F /* SnapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EEBCC9D819CC627D0083B827 /* SnapKit.framework */; }; - EE94F6091AC0F10A008767FF /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE94F6081AC0F10A008767FF /* UIKit.framework */; }; EECDB3741AC0C9B6006BBC11 /* SnapKit.h in Headers */ = {isa = PBXBuildFile; fileRef = EECDB3661AC0C95C006BBC11 /* SnapKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; EECDB3931AC0CB52006BBC11 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECDB36A1AC0C95C006BBC11 /* Tests.swift */; }; EEF68F9E1D78492400980C26 /* ConstraintLayoutGuideDSL.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEF68F9D1D78492400980C26 /* ConstraintLayoutGuideDSL.swift */; }; @@ -100,7 +99,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - EE94F6091AC0F10A008767FF /* UIKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; };