Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Commit

Permalink
Swift 4.2 migration (#1)
Browse files Browse the repository at this point in the history
* Converted to Swift 4.2

* Fix unit tests
  • Loading branch information
rsenerol authored Feb 6, 2019
1 parent 6709688 commit 75e70be
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 225 deletions.
10 changes: 7 additions & 3 deletions TZStackView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0920;
LastUpgradeCheck = 1010;
ORGANIZATIONNAME = "Tom van Zummeren";
TargetAttributes = {
5F50E36345E94CFC65ED7270 = {
Expand Down Expand Up @@ -385,12 +385,14 @@
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_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 @@ -439,12 +441,14 @@
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_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 @@ -553,7 +557,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -577,7 +581,7 @@
PRODUCT_BUNDLE_IDENTIFIER = nl.tomvanzummeren.TZStackView;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
LastUpgradeVersion = "1010"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -37,7 +36,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
12 changes: 6 additions & 6 deletions TZStackView/TZStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open class TZStackView: UIView {
}
}

public var axis: UILayoutConstraintAxis = .horizontal {
public var axis: NSLayoutConstraint.Axis = .horizontal {
didSet {
setNeedsUpdateConstraints()
}
Expand Down Expand Up @@ -348,10 +348,10 @@ open class TZStackView: UIView {
}

var topPriority: Float = 1000
var topRelation: NSLayoutRelation = .lessThanOrEqual
var topRelation: NSLayoutConstraint.Relation = .lessThanOrEqual

var bottomPriority: Float = 1000
var bottomRelation: NSLayoutRelation = .greaterThanOrEqual
var bottomRelation: NSLayoutConstraint.Relation = .greaterThanOrEqual

if alignment == .top || alignment == .leading {
topPriority = 999.5
Expand Down Expand Up @@ -437,7 +437,7 @@ open class TZStackView: UIView {
}

// Chains together the given views using Leading/Trailing or Top/Bottom
private func createFillConstraints(_ views: [UIView], priority: Float = 1000, relatedBy relation: NSLayoutRelation = .equal, constant: CGFloat) -> [NSLayoutConstraint] {
private func createFillConstraints(_ views: [UIView], priority: Float = 1000, relatedBy relation: NSLayoutConstraint.Relation = .equal, constant: CGFloat) -> [NSLayoutConstraint] {
var constraints = [NSLayoutConstraint]()

var previousView: UIView?
Expand Down Expand Up @@ -567,7 +567,7 @@ open class TZStackView: UIView {
return constraints
}

private func equalAttributes(views: [UIView], attribute: NSLayoutAttribute, priority: Float = 1000) -> [NSLayoutConstraint] {
private func equalAttributes(views: [UIView], attribute: NSLayoutConstraint.Attribute, priority: Float = 1000) -> [NSLayoutConstraint] {
var currentPriority = priority
var constraints = [NSLayoutConstraint]()
if views.count > 0 {
Expand All @@ -590,7 +590,7 @@ open class TZStackView: UIView {
}

// Convenience method to help make NSLayoutConstraint in a less verbose way
private func constraint(item view1: AnyObject, attribute attr1: NSLayoutAttribute, relatedBy relation: NSLayoutRelation = .equal, toItem view2: AnyObject?, attribute attr2: NSLayoutAttribute? = nil, multiplier: CGFloat = 1, constant c: CGFloat = 0, priority: Float = 1000) -> NSLayoutConstraint {
private func constraint(item view1: AnyObject, attribute attr1: NSLayoutConstraint.Attribute, relatedBy relation: NSLayoutConstraint.Relation = .equal, toItem view2: AnyObject?, attribute attr2: NSLayoutConstraint.Attribute? = nil, multiplier: CGFloat = 1, constant c: CGFloat = 0, priority: Float = 1000) -> NSLayoutConstraint {

let attribute2 = attr2 != nil ? attr2! : attr1

Expand Down
6 changes: 3 additions & 3 deletions TZStackViewTests/TZStackViewTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class TZStackViewTestCase: XCTestCase {
return false
}
if layoutConstraint1.priority != layoutConstraint2.priority {
if layoutConstraint1.priority < 100 || layoutConstraint1.priority > 150
|| layoutConstraint2.priority < 100 || layoutConstraint2.priority > 150 {
if layoutConstraint1.priority.rawValue < 100.0 || layoutConstraint1.priority.rawValue > 150.0
|| layoutConstraint2.priority.rawValue < 100.0 || layoutConstraint2.priority.rawValue > 150.0 {
return false
}
}
Expand Down Expand Up @@ -169,7 +169,7 @@ class TZStackViewTestCase: XCTestCase {
if object1 == nil && object2 == nil {
return true
}
if let view1 = object1 as? UIView, let view2 = object2 as? UIView , view1 == view2 {
if let view1 = object1 as? UIView, let view2 = object2 as? UIView, view1.frame == view2.frame && view1.description == view2.description {
return true
}
if object1 is UIStackView && object2 is TZStackView {
Expand Down
Loading

0 comments on commit 75e70be

Please sign in to comment.