From b014ab638a88b9ba8656e590fd96e5f898f2b101 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Sat, 11 Apr 2015 17:13:02 +1200 Subject: [PATCH] Finalise classes --- Source/Constraint.swift | 2 +- Source/ConstraintItem.swift | 2 +- Source/ConstraintMaker.swift | 2 +- Source/LayoutConstraint.swift | 4 +-- Source/View+Snap.swift | 66 +++++++++++++++++------------------ 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Source/Constraint.swift b/Source/Constraint.swift index b671494..6a91fee 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -30,7 +30,7 @@ import AppKit /** * Constraint is a single item that defines all the properties for a single ConstraintMaker chain */ -public class Constraint { +final public class Constraint { public var left: Constraint { return self.addConstraint(ConstraintAttributes.Left) } public var top: Constraint { return self.addConstraint(ConstraintAttributes.Top) } public var right: Constraint { return self.addConstraint(ConstraintAttributes.Right) } diff --git a/Source/ConstraintItem.swift b/Source/ConstraintItem.swift index 1c3c69d..ea811a5 100644 --- a/Source/ConstraintItem.swift +++ b/Source/ConstraintItem.swift @@ -30,7 +30,7 @@ import AppKit /** * ConstraintItem is a class that is used while building constraints. */ -public class ConstraintItem { +final public class ConstraintItem { internal init(object: AnyObject?, attributes: ConstraintAttributes) { self.object = object diff --git a/Source/ConstraintMaker.swift b/Source/ConstraintMaker.swift index 49e03d2..c226064 100644 --- a/Source/ConstraintMaker.swift +++ b/Source/ConstraintMaker.swift @@ -30,7 +30,7 @@ import AppKit /** * ConstraintMaker is the maker in snap that gets all constraints kickstarted */ -public class ConstraintMaker { +final public class ConstraintMaker { public var left: Constraint { return self.addConstraint(ConstraintAttributes.Left) } public var top: Constraint { return self.addConstraint(ConstraintAttributes.Top) } public var right: Constraint { return self.addConstraint(ConstraintAttributes.Right) } diff --git a/Source/LayoutConstraint.swift b/Source/LayoutConstraint.swift index 041c46e..1d92389 100644 --- a/Source/LayoutConstraint.swift +++ b/Source/LayoutConstraint.swift @@ -30,8 +30,8 @@ import AppKit /** * LayoutConstraint is a subclass of NSLayoutConstraint to assist Snap and also provide better debugging */ -public class LayoutConstraint: NSLayoutConstraint { - internal var constraint: Constraint? +final public class LayoutConstraint: NSLayoutConstraint { + internal var snp_constraint: Constraint? = nil } public func ==(left: LayoutConstraint, right: LayoutConstraint) -> Bool { diff --git a/Source/View+Snap.swift b/Source/View+Snap.swift index 09d1bab..103e8d6 100644 --- a/Source/View+Snap.swift +++ b/Source/View+Snap.swift @@ -33,69 +33,69 @@ public extension View { // normal - public var snp_left: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Left) } - public var snp_top: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Top) } - public var snp_right: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Right) } - public var snp_bottom: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Bottom) } - public var snp_leading: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Leading) } - public var snp_trailing: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Trailing) } - public var snp_width: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Width) } - public var snp_height: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Height) } - public var snp_centerX: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterX) } - public var snp_centerY: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterY) } - public var snp_baseline: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Baseline) } + final public var snp_left: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Left) } + final public var snp_top: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Top) } + final public var snp_right: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Right) } + final public var snp_bottom: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Bottom) } + final public var snp_leading: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Leading) } + final public var snp_trailing: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Trailing) } + final public var snp_width: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Width) } + final public var snp_height: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Height) } + final public var snp_centerX: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterX) } + final public var snp_centerY: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterY) } + final public var snp_baseline: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Baseline) } #if os(iOS) - public var snp_firstBaseline: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.FirstBaseline) } - public var snp_leftMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.LeftMargin) } - public var snp_rightMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.RightMargin) } - public var snp_topMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.TopMargin) } - public var snp_bottomMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.BottomMargin) } - public var snp_leadingMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.LeadingMargin) } - public var snp_trailingMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.TrailingMargin) } - public var snp_centerXWithinMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterXWithinMargins) } - public var snp_centerYWithinMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterYWithinMargins) } + final public var snp_firstBaseline: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.FirstBaseline) } + final public var snp_leftMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.LeftMargin) } + final public var snp_rightMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.RightMargin) } + final public var snp_topMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.TopMargin) } + final public var snp_bottomMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.BottomMargin) } + final public var snp_leadingMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.LeadingMargin) } + final public var snp_trailingMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.TrailingMargin) } + final public var snp_centerXWithinMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterXWithinMargins) } + final public var snp_centerYWithinMargin: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterYWithinMargins) } #endif // aggregates - public var snp_edges: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Edges) } - public var snp_size: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Size) } - public var snp_center: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Center) } + final public var snp_edges: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Edges) } + final public var snp_size: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Size) } + final public var snp_center: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Center) } #if os(iOS) - public var snp_margins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Margins) } - public var snp_centerWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterWithinMargins) } + final public var snp_margins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.Margins) } + final public var snp_centerWithinMargins: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.CenterWithinMargins) } #endif - public func snp_prepareConstraints(block: (make: ConstraintMaker) -> Void) -> Array { + final public func snp_prepareConstraints(block: (make: ConstraintMaker) -> Void) -> [Constraint] { return ConstraintMaker.prepareConstraints(self, block: block) } - public func snp_makeConstraints(block: (make: ConstraintMaker) -> Void) { + final public func snp_makeConstraints(block: (make: ConstraintMaker) -> Void) { ConstraintMaker.makeConstraints(self, block: block) } - public func snp_updateConstraints(block: (make: ConstraintMaker) -> Void) { + final public func snp_updateConstraints(block: (make: ConstraintMaker) -> Void) { ConstraintMaker.updateConstraints(self, block: block) } - public func snp_remakeConstraints(block: (make: ConstraintMaker) -> Void) { + final public func snp_remakeConstraints(block: (make: ConstraintMaker) -> Void) { ConstraintMaker.remakeConstraints(self, block: block) } - public func snp_removeConstraints() { + final public func snp_removeConstraints() { ConstraintMaker.removeConstraints(self) } // internal - internal var snp_installedLayoutConstraints: Array { + final internal var snp_installedLayoutConstraints: [LayoutConstraint] { get { - if let constraints = objc_getAssociatedObject(self, &installedLayoutConstraintsKey) as? Array { + if let constraints = objc_getAssociatedObject(self, &installedLayoutConstraintsKey) as? [LayoutConstraint] { return constraints } - return Array() + return [] } set { objc_setAssociatedObject(self, &installedLayoutConstraintsKey, newValue, UInt(OBJC_ASSOCIATION_RETAIN_NONATOMIC))