diff --git a/SnapKit.xcodeproj/project.pbxproj b/SnapKit.xcodeproj/project.pbxproj index 728dbf8..9413974 100644 --- a/SnapKit.xcodeproj/project.pbxproj +++ b/SnapKit.xcodeproj/project.pbxproj @@ -7,8 +7,8 @@ objects = { /* Begin PBXBuildFile section */ - 779230441BCB6FC30027CF5F /* SourceLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779230431BCB6FC30027CF5F /* SourceLocation.swift */; settings = {ASSET_TAGS = (); }; }; - 779230451BCB6FC30027CF5F /* SourceLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779230431BCB6FC30027CF5F /* SourceLocation.swift */; settings = {ASSET_TAGS = (); }; }; + 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 */; }; EE4910991B19A40200A54F1F /* SnapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EEBCC9D819CC627D0083B827 /* SnapKit.framework */; }; EE94F6091AC0F10A008767FF /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE94F6081AC0F10A008767FF /* UIKit.framework */; }; diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 8332df0..33a5e62 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -60,7 +60,7 @@ public class Constraint { internal var makerLocation: SourceLocation = SourceLocation(file: "Unknown", line: 0) - internal(set) public var location : SourceLocation? + internal(set) public var location: SourceLocation? } /** @@ -128,15 +128,15 @@ internal class ConcreteConstraint: Constraint { 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() @@ -153,7 +153,7 @@ internal class ConcreteConstraint: Constraint { NSLayoutConstraint.activateConstraints(layoutConstraints) } } - + internal override func deactivate() -> Void { guard self.installInfo != nil else { return @@ -195,7 +195,7 @@ internal class ConcreteConstraint: Constraint { private var installInfo: ConcreteConstraintInstallInfo? = nil - internal init(fromItem: ConstraintItem, toItem: ConstraintItem, relation: ConstraintRelation, constant: Any, multiplier: Float, priority: Float, location : SourceLocation?) { + internal init(fromItem: ConstraintItem, toItem: ConstraintItem, relation: ConstraintRelation, constant: Any, multiplier: Float, priority: Float, location: SourceLocation?) { self.fromItem = fromItem self.toItem = toItem self.relation = relation diff --git a/Source/ConstraintDescription.swift b/Source/ConstraintDescription.swift index 5a79b55..153cea7 100644 --- a/Source/ConstraintDescription.swift +++ b/Source/ConstraintDescription.swift @@ -27,87 +27,83 @@ import UIKit import AppKit #endif -// Type of object that can be a target of relation constraint. -// Doesn't cover system protocols which can't be extended with additional conformances. public protocol RelationTarget { - var constraintItem : ConstraintItem { get } + var constraintItem: ConstraintItem { get } } -// Type of things that can be converted to floats. Used to provide a catch all for -// different numeric types. -public protocol FloatConvertible : RelationTarget { - var floatValue : Float { get } +public protocol FloatConvertible: RelationTarget { + var floatValue: Float { get } } extension FloatConvertible { - public var constraintItem : ConstraintItem { + public var constraintItem: ConstraintItem { return ConstraintItem(object: nil, attributes: ConstraintAttributes.None) } } -extension Float : FloatConvertible, RelationTarget { - public var floatValue : Float { +extension Float: FloatConvertible, RelationTarget { + public var floatValue: Float { return self } } -extension Int : FloatConvertible, RelationTarget { - public var floatValue : Float { +extension Int: FloatConvertible, RelationTarget { + public var floatValue: Float { return Float(self) } } -extension UInt : FloatConvertible, RelationTarget { - public var floatValue : Float { +extension UInt: FloatConvertible, RelationTarget { + public var floatValue: Float { return Float(self) } } -extension Double : FloatConvertible, RelationTarget { - public var floatValue : Float { +extension Double: FloatConvertible, RelationTarget { + public var floatValue: Float { return Float(self) } } -extension CGFloat : FloatConvertible, RelationTarget { - public var floatValue : Float { +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 { +extension NSLayoutAnchor: RelationTarget { + public var constraintItem: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.None) } } -extension CGPoint : RelationTarget { - public var constraintItem : ConstraintItem { +extension CGPoint: RelationTarget { + public var constraintItem: ConstraintItem { return ConstraintItem(object: nil, attributes: ConstraintAttributes.None) } } -extension CGSize : RelationTarget { - public var constraintItem : ConstraintItem { +extension CGSize: RelationTarget { + public var constraintItem: ConstraintItem { return ConstraintItem(object: nil, attributes: ConstraintAttributes.None) } } -extension EdgeInsets : RelationTarget { - public var constraintItem : ConstraintItem { +extension EdgeInsets: RelationTarget { + public var constraintItem: ConstraintItem { return ConstraintItem(object: nil, attributes: ConstraintAttributes.None) } } -extension View : RelationTarget { - public var constraintItem : ConstraintItem { +extension View: RelationTarget { + public var constraintItem: ConstraintItem { return ConstraintItem(object: self, attributes: ConstraintAttributes.None) } } -extension ConstraintItem : RelationTarget { - public var constraintItem : ConstraintItem { +extension ConstraintItem: RelationTarget { + public var constraintItem: ConstraintItem { return self } } @@ -117,9 +113,9 @@ extension ConstraintItem : RelationTarget { */ public class ConstraintDescriptionFinalizable { - private let backing : ConstraintDescription + private let backing: ConstraintDescription - internal init(_ backing : ConstraintDescription) { + internal init(_ backing: ConstraintDescription) { self.backing = backing } @@ -164,7 +160,7 @@ public class ConstraintDescriptionEditable: ConstraintDescriptionPriortizable { return self.multipliedBy(1 / amount.floatValue) } - public func offset(amount : FloatConvertible) -> ConstraintDescriptionEditable { + public func offset(amount: FloatConvertible) -> ConstraintDescriptionEditable { return ConstraintDescriptionEditable(self.backing.offset(amount)) } public func offset(amount: CGPoint) -> ConstraintDescriptionEditable { @@ -190,38 +186,37 @@ public class ConstraintDescriptionEditable: ConstraintDescriptionPriortizable { */ public class ConstraintDescriptionRelatable { - private let backing : ConstraintDescription + private let backing: ConstraintDescription - init(_ backing : ConstraintDescription) { + init(_ backing: ConstraintDescription) { self.backing = backing } - - public func equalTo(other: RelationTarget, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable { + 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)) + return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .Equal, location: location)) } - public func equalTo(other: LayoutSupport, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable { + 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)) + return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .Equal, location: location)) } - public func lessThanOrEqualTo(other: RelationTarget, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable { + 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)) + return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .LessThanOrEqualTo, location: location)) } - public func lessThanOrEqualTo(other: LayoutSupport, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable { + 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)) + return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .LessThanOrEqualTo, location: location)) } - public func greaterThanOrEqualTo(other: RelationTarget, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable { + 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)) + return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .GreaterThanOrEqualTo, location: location)) } - public func greaterThanOrEqualTo(other: LayoutSupport, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable { + 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)) + return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .GreaterThanOrEqualTo, location: location)) } } @@ -307,7 +302,7 @@ public class ConstraintDescriptionExtendable: ConstraintDescriptionRelatable { */ internal class ConstraintDescription { - private var location : SourceLocation? + private var location: SourceLocation? = nil private var left: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Left) } private var top: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Top) } @@ -480,7 +475,7 @@ internal class ConstraintDescription { return self } - private func constrainTo(other: RelationTarget, relation: ConstraintRelation, location : SourceLocation) -> ConstraintDescription { + private func constrainTo(other: RelationTarget, relation: ConstraintRelation, location: SourceLocation) -> ConstraintDescription { self.location = location @@ -507,7 +502,7 @@ internal class ConstraintDescription { } @available(iOS 7.0, *) - private func constrainTo(other: LayoutSupport, relation: ConstraintRelation, location : SourceLocation) -> ConstraintDescription { + private func constrainTo(other: LayoutSupport, relation: ConstraintRelation, location: SourceLocation) -> ConstraintDescription { return constrainTo(ConstraintItem(object: other, attributes: ConstraintAttributes.None), relation: relation, location: location) } diff --git a/Source/ConstraintMaker.swift b/Source/ConstraintMaker.swift index 1c5c4b7..ec20db1 100644 --- a/Source/ConstraintMaker.swift +++ b/Source/ConstraintMaker.swift @@ -135,7 +135,7 @@ public class ConstraintMaker { } internal class func prepareConstraints(view view: View, location: SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] { - let maker = ConstraintMaker(view: view, location : location) + let maker = ConstraintMaker(view: view, location: location) closure(make: maker) let constraints = maker.constraintDescriptions.map { $0.constraint } @@ -157,7 +157,7 @@ public class ConstraintMaker { } } - internal class func remakeConstraints(view view: View, location : SourceLocation, @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, location: location) closure(make: maker) diff --git a/Source/SourceLocation.swift b/Source/SourceLocation.swift index 2feeb41..b148e49 100644 --- a/Source/SourceLocation.swift +++ b/Source/SourceLocation.swift @@ -23,10 +23,10 @@ public struct SourceLocation { - public let file : String - public let line : UInt + public let file: String + public let line: UInt - init(file : String, line : UInt) { + init(file: String, line: UInt) { self.file = file self.line = line }