Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 4.2 migration #95

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TZStackView.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "TZStackView"
s.version = "1.3.0"
s.version = "1.3.1"
s.summary = "TZStackView is a replica of iOS 9's new UIStackView for use in iOS 7 and iOS 8"
s.homepage = "https://github.com/tomvanzummeren/TZStackView.git"
s.license = { :type => "MIT" }
Expand Down
32 changes: 25 additions & 7 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 = 0800;
LastUpgradeCheck = 1010;
ORGANIZATIONNAME = "Tom van Zummeren";
TargetAttributes = {
5F50E36345E94CFC65ED7270 = {
Expand Down Expand Up @@ -381,14 +381,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
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;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -417,6 +425,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -428,14 +437,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
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;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand All @@ -456,6 +473,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -469,7 +487,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "nl.tomvanzummeren.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -485,7 +503,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "nl.tomvanzummeren.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUNDLE_LOADER)";
};
name = Release;
Expand All @@ -502,7 +520,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "nl.tomvanzummeren.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUNDLE_LOADER)";
};
name = Debug;
Expand All @@ -516,7 +534,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "nl.tomvanzummeren.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -539,7 +557,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -563,7 +581,7 @@
PRODUCT_BUNDLE_IDENTIFIER = nl.tomvanzummeren.TZStackView;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.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 = "0800"
LastUpgradeVersion = "1010"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
24 changes: 12 additions & 12 deletions TZStackView/TZStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ func ==(lhs: TZAnimationDidStopQueueEntry, rhs: TZAnimationDidStopQueueEntry) ->
return lhs.view === rhs.view
}

public class TZStackView: UIView {
open class TZStackView: UIView {

public var distribution: TZStackViewDistribution = .fill {
didSet {
setNeedsUpdateConstraints()
}
}

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

public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if let view = object as? UIView, let change = change, keyPath == "hidden" {
let hidden = view.isHidden
let previousValue = change[.oldKey] as! Bool
Expand Down Expand Up @@ -131,7 +131,7 @@ public class TZStackView: UIView {
addHiddenListener(arrangedSubview)
}

func hiddenAnimationStopped() {
@objc func hiddenAnimationStopped() {
var queueEntriesToRemove = [TZAnimationDidStopQueueEntry]()
for entry in animationDidStopQueueEntries {
let view = entry.view
Expand Down Expand Up @@ -165,11 +165,11 @@ public class TZStackView: UIView {
arrangedSubviews.insert(view, at: stackIndex)
}

override public func willRemoveSubview(_ subview: UIView) {
override open func willRemoveSubview(_ subview: UIView) {
removeArrangedSubview(subview)
}

override public func updateConstraints() {
override open func updateConstraints() {
removeConstraints(stackViewConstraints)
stackViewConstraints.removeAll()

Expand Down Expand Up @@ -348,10 +348,10 @@ public 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 @@ public 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 @@ public 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,12 +590,12 @@ public 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

let constraint = NSLayoutConstraint(item: view1, attribute: attr1, relatedBy: relation, toItem: view2, attribute: attribute2, multiplier: multiplier, constant: c)
constraint.priority = priority
constraint.priority = UILayoutPriority(rawValue: priority)
return constraint
}

Expand Down
2 changes: 1 addition & 1 deletion TZStackViewDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//Appearance proxy for the UISegmentedControl font
UISegmentedControl.appearance().setTitleTextAttributes(
[NSFontAttributeName:UIFont(name: "HelveticaNeue-Light", size:10.0)!],
[NSAttributedStringKey.font:UIFont(name: "HelveticaNeue-Light", size:10.0)!],
for: UIControlState())

//Launch the application
Expand Down
2 changes: 1 addition & 1 deletion TZStackViewDemo/ExplicitIntrinsicContentSizeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ExplicitIntrinsicContentSizeView: UIView {
isUserInteractionEnabled = true
}

func tap() {
@objc func tap() {
UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: .allowUserInteraction, animations: {
self.isHidden = true
}, completion: nil)
Expand Down
24 changes: 12 additions & 12 deletions TZStackViewDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,28 @@ class ViewController: UIViewController {
instructionLabel.text = "Tap any of the boxes to set hidden=true"
instructionLabel.textColor = UIColor.white
instructionLabel.numberOfLines = 0
instructionLabel.setContentCompressionResistancePriority(900, for: .horizontal)
instructionLabel.setContentHuggingPriority(1000, for: .vertical)
instructionLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal)
instructionLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 1000), for: .vertical)
view.addSubview(instructionLabel)

resetButton.translatesAutoresizingMaskIntoConstraints = false
resetButton.setTitle("Reset", for: UIControlState())
resetButton.addTarget(self, action: #selector(ViewController.reset), for: .touchUpInside)
resetButton.setContentCompressionResistancePriority(1000, for: .horizontal)
resetButton.setContentHuggingPriority(1000, for: .horizontal)
resetButton.setContentHuggingPriority(1000, for: .vertical)
resetButton.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 1000), for: .horizontal)
resetButton.setContentHuggingPriority(UILayoutPriority(rawValue: 1000), for: .horizontal)
resetButton.setContentHuggingPriority(UILayoutPriority(rawValue: 1000), for: .vertical)
view.addSubview(resetButton)

axisSegmentedControl = UISegmentedControl(items: ["Vertical", "Horizontal"])
axisSegmentedControl.selectedSegmentIndex = 0
axisSegmentedControl.addTarget(self, action: #selector(ViewController.axisChanged(_:)), for: .valueChanged)
axisSegmentedControl.setContentCompressionResistancePriority(900, for: .horizontal)
axisSegmentedControl.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal)
axisSegmentedControl.tintColor = UIColor.lightGray

alignmentSegmentedControl = UISegmentedControl(items: ["Fill", "Center", "Leading", "Top", "Trailing", "Bottom", "FirstBaseline"])
alignmentSegmentedControl.selectedSegmentIndex = 0
alignmentSegmentedControl.addTarget(self, action: #selector(ViewController.alignmentChanged(_:)), for: .valueChanged)
alignmentSegmentedControl.setContentCompressionResistancePriority(1000, for: .horizontal)
alignmentSegmentedControl.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 1000), for: .horizontal)
alignmentSegmentedControl.tintColor = UIColor.lightGray

distributionSegmentedControl = UISegmentedControl(items: ["Fill", "FillEqually", "FillProportionally", "EqualSpacing", "EqualCentering"])
Expand All @@ -77,7 +77,7 @@ class ViewController: UIViewController {
controlsLayoutContainer.axis = .vertical
controlsLayoutContainer.translatesAutoresizingMaskIntoConstraints = false
controlsLayoutContainer.spacing = 5
controlsLayoutContainer.setContentHuggingPriority(1000, for: .vertical)
controlsLayoutContainer.setContentHuggingPriority(UILayoutPriority(rawValue: 1000), for: .vertical)
view.addSubview(controlsLayoutContainer)

let views: [String:AnyObject] = [
Expand Down Expand Up @@ -122,7 +122,7 @@ class ViewController: UIViewController {

//MARK: - Button Actions
//--------------------------------------------------------------------------
func reset() {
@objc func reset() {
UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: .allowUserInteraction, animations: {
for view in self.tzStackView.arrangedSubviews {
view.isHidden = false
Expand All @@ -133,7 +133,7 @@ class ViewController: UIViewController {

//MARK: - Segmented Control Actions
//--------------------------------------------------------------------------
func axisChanged(_ sender: UISegmentedControl) {
@objc func axisChanged(_ sender: UISegmentedControl) {
switch sender.selectedSegmentIndex {
case 0:
tzStackView.axis = .vertical
Expand All @@ -142,7 +142,7 @@ class ViewController: UIViewController {
}
}

func alignmentChanged(_ sender: UISegmentedControl) {
@objc func alignmentChanged(_ sender: UISegmentedControl) {
switch sender.selectedSegmentIndex {
case 0:
tzStackView.alignment = .fill
Expand All @@ -162,7 +162,7 @@ class ViewController: UIViewController {
tzStackView.setNeedsUpdateConstraints()
}

func distributionChanged(_ sender: UISegmentedControl) {
@objc func distributionChanged(_ sender: UISegmentedControl) {
switch sender.selectedSegmentIndex {
case 0:
tzStackView.distribution = .fill
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