Skip to content
This repository was archived by the owner on Jul 13, 2022. It is now read-only.

Commit 1d9c99c

Browse files
Sidharth Juyalkean
Sidharth Juyal
authored andcommitted
Upgrade to swift 4.2
1 parent 8c17a1d commit 1d9c99c

10 files changed

+63
-63
lines changed

Example/Example.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@
343343
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
344344
PRODUCT_BUNDLE_IDENTIFIER = com.github.kean.Example;
345345
PRODUCT_NAME = "$(TARGET_NAME)";
346-
SWIFT_VERSION = 3.0;
346+
SWIFT_VERSION = 4.2;
347347
};
348348
name = Debug;
349349
};
@@ -358,7 +358,7 @@
358358
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
359359
PRODUCT_BUNDLE_IDENTIFIER = com.github.kean.Example;
360360
PRODUCT_NAME = "$(TARGET_NAME)";
361-
SWIFT_VERSION = 3.0;
361+
SWIFT_VERSION = 4.2;
362362
};
363363
name = Release;
364364
};

Example/Example/Adapter.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,39 @@ protocol StackViewAdapter: class {
1414
// Those members are the same for both classes
1515
func addArrangedSubview(_ view: UIView)
1616
func removeArrangedSubview(_ view: UIView)
17-
var axis: UILayoutConstraintAxis { get set }
17+
var axis: NSLayoutConstraint.Axis { get set }
1818
var spacing: CGFloat { get set }
1919
var isBaselineRelativeArrangement: Bool { get set }
2020
var isLayoutMarginsRelativeArrangement: Bool { get set }
2121

22-
var ar_distribution: UIStackViewDistribution { get set }
23-
var ar_alignment: UIStackViewAlignment { get set }
22+
var ar_distribution: UIStackView.Distribution { get set }
23+
var ar_alignment: UIStackView.Alignment { get set }
2424
}
2525

2626
extension StackView: StackViewAdapter {
27-
var ar_distribution: UIStackViewDistribution {
27+
var ar_distribution: UIStackView.Distribution {
2828
get { return self.distribution.toStackViewDistrubition() }
2929
set { self.distribution = StackViewDistribution.fromStackViewDistrubition(newValue) }
3030
}
31-
var ar_alignment: UIStackViewAlignment {
31+
var ar_alignment: UIStackView.Alignment {
3232
get { return self.alignment.toStackViewAlignment() }
3333
set { self.alignment = StackViewAlignment.fromStackViewAlignment(newValue) }
3434
}
3535
}
3636

3737
extension UIStackView: StackViewAdapter {
38-
var ar_distribution: UIStackViewDistribution {
38+
var ar_distribution: UIStackView.Distribution {
3939
get { return self.distribution }
4040
set { self.distribution = newValue }
4141
}
42-
var ar_alignment: UIStackViewAlignment {
42+
var ar_alignment: UIStackView.Alignment {
4343
get { return self.alignment }
4444
set { self.alignment = newValue }
4545
}
4646
}
4747

4848
extension StackViewDistribution {
49-
func toStackViewDistrubition() -> UIStackViewDistribution {
49+
func toStackViewDistrubition() -> UIStackView.Distribution {
5050
switch self {
5151
case .fill: return .fill
5252
case .fillEqually: return .fillEqually
@@ -56,7 +56,7 @@ extension StackViewDistribution {
5656
}
5757
}
5858

59-
static func fromStackViewDistrubition(_ distribution: UIStackViewDistribution) -> StackViewDistribution {
59+
static func fromStackViewDistrubition(_ distribution: UIStackView.Distribution) -> StackViewDistribution {
6060
switch distribution {
6161
case .fill: return .fill
6262
case .fillEqually: return .fillEqually
@@ -68,7 +68,7 @@ extension StackViewDistribution {
6868
}
6969

7070
extension StackViewAlignment {
71-
func toStackViewAlignment() -> UIStackViewAlignment {
71+
func toStackViewAlignment() -> UIStackView.Alignment {
7272
switch self {
7373
case .fill: return .fill
7474
case .leading: return .leading
@@ -79,7 +79,7 @@ extension StackViewAlignment {
7979
}
8080
}
8181

82-
static func fromStackViewAlignment(_ alignment: UIStackViewAlignment) -> StackViewAlignment {
82+
static func fromStackViewAlignment(_ alignment: UIStackView.Alignment) -> StackViewAlignment {
8383
switch alignment {
8484
case .fill: return .fill
8585
case .leading: return .leading

Example/Example/AppDelegate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
1616
let controller1 = ArrangedViewController()
1717
let controller2 = StackViewController()
1818

19-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
19+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
2020
window = UIWindow(frame: UIScreen.main.bounds)
2121
window?.backgroundColor = UIColor.white
2222
controller1.tabBarItem = UITabBarItem(title: "Arranged.StackView", image: UIImage(named: "tabBarIcon"), tag: 0)

Example/Example/BaseStackViewController.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class BaseStackViewController<T>: UIViewController where T: UIView, T: StackView
6161

6262
refreshContent()
6363

64-
stackView.layoutMargins = UIEdgeInsetsMake(8, 8, 8, 8)
64+
stackView.layoutMargins = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)
6565

6666
view.layoutMargins = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
6767
view.addSubview(stackView)
@@ -75,10 +75,10 @@ class BaseStackViewController<T>: UIViewController where T: UIView, T: StackView
7575

7676
// Disambiguate stack view size
7777
stackView.addConstraint(NSLayoutConstraint(item: stackView, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 0).then {
78-
$0.priority = 100
78+
$0.priority = UILayoutPriority(rawValue: 100)
7979
})
8080
stackView.addConstraint(NSLayoutConstraint(item: stackView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 0).then {
81-
$0.priority = 100
81+
$0.priority = UILayoutPriority(rawValue: 100)
8282
})
8383

8484
// Create background for stack view
@@ -144,7 +144,7 @@ class BaseStackViewController<T>: UIViewController where T: UIView, T: StackView
144144
controls2.isLayoutMarginsRelativeArrangement = true
145145
controls2.alignment = .trailing
146146
controls2.addArrangedSubview(UIButton(type: .system).then {
147-
$0.setTitle("show all subviews", for: UIControlState())
147+
$0.setTitle("show all subviews", for: UIControl.State())
148148
$0.addTarget(self, action: #selector(BaseStackViewController.buttonShowAllTapped(_:)), for: .touchUpInside)
149149
})
150150
controls2.addArrangedSubview(AnimatedPicker(value: self.animated, presenter: self) {
@@ -287,7 +287,7 @@ class BaseStackViewController<T>: UIViewController where T: UIView, T: StackView
287287
}
288288
}
289289

290-
func perform(_ closure: @escaping (Void) -> Void) {
290+
func perform(_ closure: @escaping () -> Void) {
291291
if (animated) {
292292
UIView.animate(withDuration: 0.33, animations: {
293293
closure()

Example/Example/Picker.swift

+13-13
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ class ValuePicker<Value> {
6666
}
6767
}
6868

69-
class AxisPicker : ValuePicker<UILayoutConstraintAxis> {
70-
override init(value: UILayoutConstraintAxis, presenter: UIViewController, observer: @escaping (_ value: UILayoutConstraintAxis) -> Void) {
69+
class AxisPicker : ValuePicker<NSLayoutConstraint.Axis> {
70+
override init(value: NSLayoutConstraint.Axis, presenter: UIViewController, observer: @escaping (_ value: NSLayoutConstraint.Axis) -> Void) {
7171
super.init(value: value, presenter: presenter, observer: observer)
7272
}
7373

@@ -99,11 +99,11 @@ class SpacingPicker : ValuePicker<CGFloat> {
9999
}
100100
}
101101

102-
class DistrubituonPicker : ValuePicker<UIStackViewDistribution> {
103-
let values: [UIStackViewDistribution] = [.fill, .fillEqually, .fillProportionally, .equalSpacing, .equalCentering]
102+
class DistrubituonPicker : ValuePicker<UIStackView.Distribution> {
103+
let values: [UIStackView.Distribution] = [.fill, .fillEqually, .fillProportionally, .equalSpacing, .equalCentering]
104104
let items = [".Fill", ".FillEqually", ".FillProportionally", ".EqualSpacing", ".EqualCentering"]
105105

106-
override init(value: UIStackViewDistribution, presenter: UIViewController, observer: @escaping (_ value: UIStackViewDistribution) -> Void) {
106+
override init(value: UIStackView.Distribution, presenter: UIViewController, observer: @escaping (_ value: UIStackView.Distribution) -> Void) {
107107
super.init(value: value, presenter: presenter, observer: observer)
108108
}
109109

@@ -118,11 +118,11 @@ class DistrubituonPicker : ValuePicker<UIStackViewDistribution> {
118118
}
119119
}
120120

121-
class AlignmentPicker : ValuePicker<UIStackViewAlignment> {
122-
let values: [UIStackViewAlignment] = [.fill, .leading, .firstBaseline, .center, .trailing, .lastBaseline]
121+
class AlignmentPicker : ValuePicker<UIStackView.Alignment> {
122+
let values: [UIStackView.Alignment] = [.fill, .leading, .firstBaseline, .center, .trailing, .lastBaseline]
123123
let items = [".Fill", ".Leading", ".FirstBaseline", ".Center", ".Trailing", ".LastBaseline"]
124124

125-
override init(value: UIStackViewAlignment, presenter: UIViewController, observer: @escaping (_ value: UIStackViewAlignment) -> Void) {
125+
override init(value: UIStackView.Alignment, presenter: UIViewController, observer: @escaping (_ value: UIStackView.Alignment) -> Void) {
126126
super.init(value: value, presenter: presenter, observer: observer)
127127
}
128128

@@ -138,7 +138,7 @@ class AlignmentPicker : ValuePicker<UIStackViewAlignment> {
138138
}
139139

140140
class MarginsPicker : ValuePicker<UIEdgeInsets> {
141-
let values: [UIEdgeInsets] = [UIEdgeInsetsMake(8, 8, 8, 8) , UIEdgeInsetsMake(10, 20, 30, 40), UIEdgeInsets.zero]
141+
let values: [UIEdgeInsets] = [UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8) , UIEdgeInsets(top: 10, left: 20, bottom: 30, right: 40), UIEdgeInsets.zero]
142142
let items = ["(8, 8, 8, 8)", "(10, 20, 30, 40)", "(0, 0, 0, 0)"]
143143

144144
override init(value: UIEdgeInsets, presenter: UIViewController, observer: @escaping (_ value: UIEdgeInsets) -> Void) {
@@ -228,7 +228,7 @@ class SizePicker: ValuePicker<(Bool, CGFloat)> {
228228
super.init(value: value, presenter: presenter, observer: observer)
229229

230230
let prefix = type == .width ? "H:" : "V:"
231-
button.setTitle("\(prefix) pin", for: UIControlState())
231+
button.setTitle("\(prefix) pin", for: UIControl.State())
232232
button.setTitle("\(prefix) unpin", for: .selected)
233233

234234
let slider = UISlider()
@@ -261,8 +261,8 @@ class SizePicker: ValuePicker<(Bool, CGFloat)> {
261261
extension UIButton {
262262
func setTitle(_ title: String, value: String) {
263263
let string = NSMutableAttributedString()
264-
string.append(NSAttributedString(string: title + " ", attributes: [ NSFontAttributeName: UIFont.systemFont(ofSize: 14) ]))
265-
string.append(NSAttributedString(string: value, attributes: [ NSFontAttributeName: UIFont.boldSystemFont(ofSize: 14) ]))
266-
self.setAttributedTitle(string, for: UIControlState())
264+
string.append(NSAttributedString(string: title + " ", attributes: [ NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14) ]))
265+
string.append(NSAttributedString(string: value, attributes: [ NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 14) ]))
266+
self.setAttributedTitle(string, for: UIControl.State())
267267
}
268268
}

Sources/AlignedLayoutArrangement.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class AlignedLayoutArrangement: LayoutArrangement {
9494
}
9595

9696
private func updateAlignmentConstraints() {
97-
func attributes() -> [NSLayoutAttribute] {
97+
func attributes() -> [NSLayoutConstraint.Attribute] {
9898
switch type {
9999
case .fill: return [bottom, top]
100100
case .leading: return [top]
@@ -111,33 +111,33 @@ class AlignedLayoutArrangement: LayoutArrangement {
111111

112112
// MARK: Managed Attributes
113113

114-
private var height: NSLayoutAttribute {
114+
private var height: NSLayoutConstraint.Attribute {
115115
return axis == .horizontal ? .height : .width
116116
}
117117

118-
private var top: NSLayoutAttribute {
118+
private var top: NSLayoutConstraint.Attribute {
119119
return axis == .horizontal ? .top : .leading
120120
}
121121

122-
private var bottom: NSLayoutAttribute {
122+
private var bottom: NSLayoutConstraint.Attribute {
123123
return axis == .horizontal ? .bottom : .trailing
124124
}
125125

126-
private var center: NSLayoutAttribute {
126+
private var center: NSLayoutConstraint.Attribute {
127127
return axis == .horizontal ? .centerY : .centerX
128128
}
129129

130130
// MARK: Helpers
131131

132-
private func alignItems(_ items: [UIView], attribute: NSLayoutAttribute) {
132+
private func alignItems(_ items: [UIView], attribute: NSLayoutConstraint.Attribute) {
133133
let firstItem = items.first!
134134
items.dropFirst().forEach {
135135
constraint(item: firstItem, attribute: attribute, toItem: $0, attribute: nil, identifier: "ASV-alignment")
136136
}
137137
}
138138

139139
private func connectItemsToSpacer(_ spacer: LayoutSpacer, items: [UIView], topWeak: Bool, bottomWeak: Bool) {
140-
func connectToSpacer(_ item: UIView, attribute attr: NSLayoutAttribute, weak: Bool) {
140+
func connectToSpacer(_ item: UIView, attribute attr: NSLayoutConstraint.Attribute, weak: Bool) {
141141
let relation = connectionRelation(attr, weak: weak)
142142
let priority: UILayoutPriority? = weak ? nil : UILayoutPriority(rawValue: 999.5)
143143
constraint(item: spacer, attribute: attr, toItem: item, relation: relation, priority: priority, identifier: "ASV-spanning-boundary")

Sources/DistributionLayoutArrangement.swift

+13-13
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ class DistributionLayoutArrangement: LayoutArrangement {
6868
canvas.addSubview(gap)
6969
gaps.append(gap)
7070

71-
let toAttr: NSLayoutAttribute = isBaselineRelative ? .firstBaseline : leading
72-
let fromAttr: NSLayoutAttribute = isBaselineRelative ? .lastBaseline : trailing
71+
let toAttr: NSLayoutConstraint.Attribute = isBaselineRelative ? .firstBaseline : leading
72+
let fromAttr: NSLayoutConstraint.Attribute = isBaselineRelative ? .lastBaseline : trailing
7373

7474
connectItem(gap, attribute: toAttr, item: previous, attribute: (type == .equalCentering ? center : fromAttr))
7575
connectItem(gap, attribute: fromAttr, item: current, attribute: (type == .equalCentering ? center : toAttr))
7676
}
77-
matchItemsSize(gaps, priority: type == .equalCentering ? UILayoutPriority(rawValue: 149) : nil)
77+
matchItemsSize(gaps, priority: type == .equalCentering ? UILayoutPriority(rawValue:149) : nil)
7878
}
7979

8080
private func updateDistributionConstraints() {
@@ -94,7 +94,7 @@ class DistributionLayoutArrangement: LayoutArrangement {
9494
}
9595
let itemsWithIntrinsic: [UIView] = visibleItems.filter {
9696
let size = sizeFor($0)
97-
return size != UIViewNoIntrinsicMetric && size > 0
97+
return size != UIView.noIntrinsicMetric && size > 0
9898
}
9999
guard itemsWithIntrinsic.count > 0 else {
100100
matchItemsSize(visibleItems)
@@ -107,7 +107,7 @@ class DistributionLayoutArrangement: LayoutArrangement {
107107
var priority: UILayoutPriority? = (itemsWithIntrinsic.count == 1 && (visibleItems.count == 1 || spacing == 0.0)) ? nil : UILayoutPriority(rawValue: 999)
108108
visibleItems.forEach {
109109
let size = sizeFor($0)
110-
if size != UIViewNoIntrinsicMetric && size > 0 {
110+
if size != UIView.noIntrinsicMetric && size > 0 {
111111
constraint(item: $0, attribute: width, toItem: canvas, relation: .equal, multiplier: (size / totalSize), priority: priority, identifier: "ASV-fill-proportionally")
112112
} else {
113113
constraint(item: $0, attribute: width, constant: 0, identifier: "ASV-fill-proportionally")
@@ -126,26 +126,26 @@ class DistributionLayoutArrangement: LayoutArrangement {
126126

127127
// MARK: Managed Attributes
128128

129-
private var width: NSLayoutAttribute {
129+
private var width: NSLayoutConstraint.Attribute {
130130
return axis == .horizontal ? .width : .height
131131
}
132132

133-
private var leading: NSLayoutAttribute {
133+
private var leading: NSLayoutConstraint.Attribute {
134134
return axis == .horizontal ? .leading : .top
135135
}
136136

137-
private var trailing: NSLayoutAttribute {
137+
private var trailing: NSLayoutConstraint.Attribute {
138138
return axis == .horizontal ? .trailing : .bottom
139139
}
140140

141-
private var center: NSLayoutAttribute {
141+
private var center: NSLayoutConstraint.Attribute {
142142
return axis == .horizontal ? .centerX : .centerY
143143
}
144144

145145

146146
// MARK: Helpers
147147

148-
private func addSpacings(_ relation: NSLayoutRelation = .equal) {
148+
private func addSpacings(_ relation: NSLayoutConstraint.Relation = .equal) {
149149
func spacingFor(previous: UIView, current: UIView) -> CGFloat {
150150
if current === visibleItems.first || previous === visibleItems.last {
151151
return 0.0
@@ -155,13 +155,13 @@ class DistributionLayoutArrangement: LayoutArrangement {
155155
}
156156
items.forPair { previous, current in
157157
let spacing = spacingFor(previous: previous, current: current)
158-
let toAttr: NSLayoutAttribute = isBaselineRelative ? .firstBaseline : leading
159-
let fromAttr: NSLayoutAttribute = isBaselineRelative ? .lastBaseline : trailing
158+
let toAttr: NSLayoutConstraint.Attribute = isBaselineRelative ? .firstBaseline : leading
159+
let fromAttr: NSLayoutConstraint.Attribute = isBaselineRelative ? .lastBaseline : trailing
160160
constraint(item: current, attribute: toAttr, toItem: previous, attribute: fromAttr, relation: relation, constant: spacing, identifier: "ASV-spacing")
161161
}
162162
}
163163

164-
private func connectItem(_ item1: UIView, attribute attr1: NSLayoutAttribute, item item2: UIView, attribute attr2: NSLayoutAttribute) {
164+
private func connectItem(_ item1: UIView, attribute attr1: NSLayoutConstraint.Attribute, item item2: UIView, attribute attr2: NSLayoutConstraint.Attribute) {
165165
constraint(item: item1, attribute: attr1, toItem: item2, attribute: attr2, identifier: "ASV-distributing-edge")
166166
}
167167

Sources/Internal.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ extension Sequence {
4545
}
4646

4747

48-
extension NSLayoutAttribute {
49-
var toMargin: NSLayoutAttribute {
48+
extension NSLayoutConstraint.Attribute {
49+
var toMargin: NSLayoutConstraint.Attribute {
5050
switch self {
5151
case .left: return .leftMargin
5252
case .right: return .rightMargin

0 commit comments

Comments
 (0)