Răsfoiți Sursa

Switch makerFile/line to use SourceLocation for consistency

Allows removing redundant default location
Akiva Leffert 10 ani în urmă
părinte
comite
0fe4ad005b

+ 6 - 7
Source/Constraint.swift

@@ -58,8 +58,7 @@ public class Constraint {
     public func updatePriorityMedium() -> Void { fatalError("Must be implemented by Concrete subclass.") }
     public func updatePriorityLow() -> Void { fatalError("Must be implemented by Concrete subclass.") }
     
-    internal var makerFile: String = "Unknown"
-    internal var makerLine: UInt = 0
+    internal var makerLocation: SourceLocation = SourceLocation(file: "Unknown", line: 0)
     
     internal(set) public var location : SourceLocation?
 }
@@ -131,7 +130,7 @@ internal class ConcreteConstraint: Constraint {
     }
     
     internal override func install() -> [LayoutConstraint] {
-        return self.installOnView(updateExisting: false, file: self.makerFile, line: self.makerLine)
+        return self.installOnView(updateExisting: false, location: self.makerLocation)
     }
     
     internal override func uninstall() -> Void {
@@ -207,12 +206,12 @@ internal class ConcreteConstraint: Constraint {
         self.location = location
     }
     
-    internal func installOnView(updateExisting updateExisting: Bool = false, file: String? = nil, line: UInt? = nil) -> [LayoutConstraint] {
+    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.makerFile)#\(self.makerLine))", userInfo: nil).raise()
+                NSException(name: "Cannot Install Constraint", reason: "No common superview between views (@\(self.makerLocation.file)#\(self.makerLocation.line))", userInfo: nil).raise()
                 return []
             }
         } else {
@@ -222,7 +221,7 @@ internal class ConcreteConstraint: Constraint {
             } else {
                 installOnView = self.fromItem.view?.superview
                 if installOnView == nil {
-                    NSException(name: "Cannot Install Constraint", reason: "Missing superview (@\(self.makerFile)#\(self.makerLine))", userInfo: nil).raise()
+                    NSException(name: "Cannot Install Constraint", reason: "Missing superview (@\(self.makerLocation.file)#\(self.self.makerLocation.line))", userInfo: nil).raise()
                     return []
                 }
             }
@@ -230,7 +229,7 @@ internal class ConcreteConstraint: Constraint {
         
         if let installedOnView = self.installInfo?.view {
             if installedOnView != installOnView {
-                NSException(name: "Cannot Install Constraint", reason: "Already installed on different view. (@\(self.makerFile)#\(self.makerLine))", userInfo: nil).raise()
+                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] ?? []

+ 15 - 21
Source/ConstraintMaker.swift

@@ -118,14 +118,12 @@ public class ConstraintMaker {
     @available(iOS 8.0, *)
     public var centerWithinMargins: ConstraintDescriptionExtendable { return self.makeConstraintDescription(ConstraintAttributes.CenterWithinMargins) }
     
-    internal init(view: View, file: String, line: UInt) {
+    internal init(view: View, location: SourceLocation) {
         self.view = view
-        self.file = file
-        self.line = line
+        self.location = location
     }
     
-    internal let file: String
-    internal let line: UInt
+    internal let location: SourceLocation
     internal let view: View
     internal var constraintDescriptions = [ConstraintDescription]()
     
@@ -136,54 +134,50 @@ public class ConstraintMaker {
         return ConstraintDescriptionExtendable(constraintDescription)
     }
     
-    internal class func prepareConstraints(view view: View, file: String = "Unknown", line: UInt = 0, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] {
-        let maker = ConstraintMaker(view: view, file: file, line: line)
+    internal class func prepareConstraints(view view: View, location: SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] {
+        let maker = ConstraintMaker(view: view, location : location)
         closure(make: maker)
         
         let constraints = maker.constraintDescriptions.map { $0.constraint }
         for constraint in constraints {
-            constraint.makerFile = maker.file
-            constraint.makerLine = maker.line
+            constraint.makerLocation = maker.location
         }
         return constraints
     }
     
-    internal class func makeConstraints(view view: View, file: String = "Unknown", line: UInt = 0, @noescape closure: (make: ConstraintMaker) -> Void) {
+    internal class func makeConstraints(view view: View, location: SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) {
         view.translatesAutoresizingMaskIntoConstraints = false
-        let maker = ConstraintMaker(view: view, file: file, line: line)
+        let maker = ConstraintMaker(view: view, location: location)
         closure(make: maker)
         
         let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint }
         for constraint in constraints {
-            constraint.makerFile = maker.file
-            constraint.makerLine = maker.line
+            constraint.makerLocation = maker.location
             constraint.installOnView(updateExisting: false)
         }
     }
     
-    internal class func remakeConstraints(view view: View, file: String = "Unknown", line: UInt = 0, @noescape closure: (make: ConstraintMaker) -> Void) {
+    internal class func remakeConstraints(view view: View, location : SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) {
         view.translatesAutoresizingMaskIntoConstraints = false
-        let maker = ConstraintMaker(view: view, file: file, line: line)
+        let maker = ConstraintMaker(view: view, location: location)
         closure(make: maker)
         
         self.removeConstraints(view: view)
         let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint }
         for constraint in constraints {
-            constraint.makerFile = maker.file
-            constraint.makerLine = maker.line
+            constraint.makerLocation = maker.location
             constraint.installOnView(updateExisting: false)
         }
     }
     
-    internal class func updateConstraints(view view: View, file: String = "Unknown", line: UInt = 0, @noescape closure: (make: ConstraintMaker) -> Void) {
+    internal class func updateConstraints(view view: View, location: SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) {
         view.translatesAutoresizingMaskIntoConstraints = false
-        let maker = ConstraintMaker(view: view, file: file, line: line)
+        let maker = ConstraintMaker(view: view, location: location)
         closure(make: maker)
         
         let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint}
         for constraint in constraints {
-            constraint.makerFile = maker.file
-            constraint.makerLine = maker.line
+            constraint.makerLocation = maker.location
             constraint.installOnView(updateExisting: true)
         }
     }

+ 2 - 2
Source/Debugging.swift

@@ -101,11 +101,11 @@ public extension LayoutConstraint {
     }
     
     internal var snp_makerFile: String? {
-        return self.snp_constraint?.makerFile
+        return self.snp_constraint?.makerLocation.file
     }
     
     internal var snp_makerLine: UInt? {
-        return self.snp_constraint?.makerLine
+        return self.snp_constraint?.makerLocation.line
     }
     
 }

+ 4 - 4
Source/View+SnapKit.swift

@@ -128,7 +128,7 @@ public extension View {
         :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, file: file, line: line, closure: closure)
+        return ConstraintMaker.prepareConstraints(view: self, location: SourceLocation(file: file, line: line), closure: closure)
     }
     
     /**
@@ -137,7 +137,7 @@ public extension View {
         :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, file: file, line: line, closure: closure)
+        ConstraintMaker.makeConstraints(view: self, location: SourceLocation(file: file, line: line), closure: closure)
     }
     
     /**
@@ -148,7 +148,7 @@ public extension View {
         :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, file: file, line: line, closure: closure)
+        ConstraintMaker.updateConstraints(view: self, location: SourceLocation(file: file, line: line), closure: closure)
     }
     
     /**
@@ -157,7 +157,7 @@ public extension View {
         :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, file: file, line: line, closure: closure)
+        ConstraintMaker.remakeConstraints(view: self, location: SourceLocation(file: file, line: line), closure: closure)
     }
     
     /**