Skip to content

Commit

Permalink
New version 1.1.0
Browse files Browse the repository at this point in the history
- Cache for 'open var nsLayoutConstraint: NSLayoutConstraint?' at LayoutDescription.
- Fixed bug at LayoutFactories.
- Added some comments.
- Upgrade to Swift 4.1.
  • Loading branch information
SashaZolotarev committed Apr 6, 2018
1 parent f361c32 commit 2057952
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
20 changes: 13 additions & 7 deletions Source/LayoutDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions Source/LayoutFactories.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Source/LayoutTraits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
4 changes: 2 additions & 2 deletions SuperPuperDuperLayout.podspec
Original file line number Diff line number Diff line change
@@ -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.'
Expand All @@ -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
6 changes: 5 additions & 1 deletion SuperPuperDuperLayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 0920;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "Sugar And Candy";
TargetAttributes = {
769CC029204ECA6A009F3445 = {
Expand Down Expand Up @@ -332,13 +332,15 @@
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;
CLANG_WARN_ENUM_CONVERSION = YES;
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;
Expand Down Expand Up @@ -392,13 +394,15 @@
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;
CLANG_WARN_ENUM_CONVERSION = YES;
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;
Expand Down

0 comments on commit 2057952

Please sign in to comment.