From 2057952323fbad0c331f1e6eeab6efdfe18daa32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=97=D0=BE=D0=BB=D0=BE=D1=82=D0=B0=D1=80=D0=B5=CC=88=D0=B2?= Date: Sat, 7 Apr 2018 01:27:46 +0300 Subject: [PATCH] New version 1.1.0 - Cache for 'open var nsLayoutConstraint: NSLayoutConstraint?' at LayoutDescription. - Fixed bug at LayoutFactories. - Added some comments. - Upgrade to Swift 4.1. --- Source/LayoutDescription.swift | 20 ++++++++++++------- Source/LayoutFactories.swift | 4 +--- .../LayoutOptionsForSingleConstraint.swift | 1 + Source/LayoutTraits.swift | 3 +++ SuperPuperDuperLayout.podspec | 4 ++-- .../project.pbxproj | 6 +++++- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Source/LayoutDescription.swift b/Source/LayoutDescription.swift index 6291efb..9191809 100644 --- a/Source/LayoutDescription.swift +++ b/Source/LayoutDescription.swift @@ -59,19 +59,25 @@ open class LayoutDescription { open var constant = CGFloat(0) open var nsLayoutConstraint: NSLayoutConstraint? { + guard _nsLayoutConstraint == nil else { return _nsLayoutConstraint } guard let firstItem = firstItem.someItem else { return nil } guard firstAttribute != .notAnAttribute else { return nil } guard let relation = relation else { return nil } guard secondItem == nil || secondAttribute != .notAnAttribute else { return nil } if secondItem == nil { secondAttribute = firstAttribute } - return NSLayoutConstraint(item: firstItem, - attribute: firstAttribute, - relatedBy: relation, - toItem: secondItem?.someItem, - attribute: secondAttribute, - multiplier: CGFloat(multiplier), - constant: constant) + _nsLayoutConstraint = NSLayoutConstraint(item: firstItem, + attribute: firstAttribute, + relatedBy: relation, + toItem: secondItem?.someItem, + attribute: secondAttribute, + multiplier: CGFloat(multiplier), + constant: constant) + _nsLayoutConstraint?.shouldBeArchived = true + return _nsLayoutConstraint } + + /// Cached 'open var nsLayoutConstraint: NSLayoutConstraint?' + private weak var _nsLayoutConstraint: NSLayoutConstraint? } open class EditableItem { diff --git a/Source/LayoutFactories.swift b/Source/LayoutFactories.swift index f926cf7..0418ca0 100644 --- a/Source/LayoutFactories.swift +++ b/Source/LayoutFactories.swift @@ -63,7 +63,7 @@ open class ConstraintFactory { internal func setup() { (firstItem.someItem as? UIView)?.translatesAutoresizingMaskIntoConstraints = false - NSLayoutConstraint.activate(layoutDescriptions.flatMap { $0.nsLayoutConstraint }) + NSLayoutConstraint.activate(layoutDescriptions.compactMap { $0.nsLayoutConstraint }) } fileprivate func layoutDescription(for attribute: NSLayoutAttribute) -> LayoutDescription { @@ -120,7 +120,6 @@ open class ConstraintLayoutGuideFactory: ConstraintFactory, VerticalAxisLayoutTr let bottomLayoutDescription = layoutDescription(for: .bottom) let leadingLayoutDescription = layoutDescription(for: .leading) let trailingLayoutDescription = layoutDescription(for: .trailing) - layoutDescriptions.append(contentsOf: [topLayoutDescription, bottomLayoutDescription, leadingLayoutDescription, trailingLayoutDescription]) return EdgesLayoutAttributeType(top: topLayoutDescription, bottom: bottomLayoutDescription, leading: leadingLayoutDescription, @@ -130,7 +129,6 @@ open class ConstraintLayoutGuideFactory: ConstraintFactory, VerticalAxisLayoutTr open var size: SizeLayoutAttributeType { let widthLayoutDescription = layoutDescription(for: .width) let heightLayoutDescription = layoutDescription(for: .height) - layoutDescriptions.append(contentsOf: [widthLayoutDescription, heightLayoutDescription]) return SizeLayoutAttributeType(width: widthLayoutDescription, height: heightLayoutDescription) } diff --git a/Source/LayoutOptions/LayoutOptionsForSingleConstraint.swift b/Source/LayoutOptions/LayoutOptionsForSingleConstraint.swift index 7fc3819..ed053e1 100644 --- a/Source/LayoutOptions/LayoutOptionsForSingleConstraint.swift +++ b/Source/LayoutOptions/LayoutOptionsForSingleConstraint.swift @@ -26,6 +26,7 @@ import UIKit open class LayoutOptionsForSingleConstraint: LayoutOptions, LayoutOptionsEditableValueProtocol { public typealias ValueType = CGFloat + @discardableResult open func value(_ value: ValueType) -> Self { layoutDescription.constant = value diff --git a/Source/LayoutTraits.swift b/Source/LayoutTraits.swift index e87332e..47075b5 100644 --- a/Source/LayoutTraits.swift +++ b/Source/LayoutTraits.swift @@ -63,7 +63,10 @@ public protocol ExtendedLayoutTraits { associatedtype EdgesLayoutAttributeType associatedtype SizeLayoutAttributeType associatedtype CenterLayoutAttributeType + /// Creates constraint for all edges: top, bottom, leading, trailing var edges: EdgesLayoutAttributeType { get } + /// Creates constraint for all size values: width, height var size: SizeLayoutAttributeType { get } + /// Creates constraint for all center values: centerX, centerY var center: CenterLayoutAttributeType { get } } diff --git a/SuperPuperDuperLayout.podspec b/SuperPuperDuperLayout.podspec index 7636ea9..c3957a0 100644 --- a/SuperPuperDuperLayout.podspec +++ b/SuperPuperDuperLayout.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'SuperPuperDuperLayout' - s.version = '1.0.2' + s.version = '1.1.0' s.license = 'MIT' s.summary = 'Lightweight, elegant and safe wrapper over auto layout.' s.description = 'Lightweight, elegant and safe wrapper over auto layout. Inspired by Layout Anchors ( https://developer.apple.com/documentation/uikit/nslayoutanchor ) and SnapKit ( https://github.com/SnapKit/SnapKit ). Without overheads such as «extension UIView», «extension UILayoutGuide», «objc_setAssociatedObjectAssociatedObject», «objc_getAssociatedObject» etc.' @@ -10,5 +10,5 @@ Pod::Spec.new do |s| s.source = { :git => 'https://github.com/SugarAndCandy/SuperPuperDuperLayout.git', :tag => s.version } s.ios.deployment_target = '8.0' s.source_files = 'Source/**/*.swift' - s.swift_version = '4' + s.swift_version = '4.1' end diff --git a/SuperPuperDuperLayout.xcodeproj/project.pbxproj b/SuperPuperDuperLayout.xcodeproj/project.pbxproj index dc82437..228dad0 100644 --- a/SuperPuperDuperLayout.xcodeproj/project.pbxproj +++ b/SuperPuperDuperLayout.xcodeproj/project.pbxproj @@ -219,7 +219,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 0920; + LastUpgradeCheck = 0930; ORGANIZATIONNAME = "Sugar And Candy"; TargetAttributes = { 769CC029204ECA6A009F3445 = { @@ -332,6 +332,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -339,6 +340,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -392,6 +394,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -399,6 +402,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;