Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Swift 4.2 migration #244

Open
wants to merge 4 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 .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1
4.2
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode9.3
osx_image: xcode10
script: sh build.sh /tmp/LayoutKit
after_success:
- bash <(curl -s https://codecov.io/bash) -D /tmp/LayoutKit
6 changes: 4 additions & 2 deletions LayoutKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
SWIFT_VERSION = 4.1;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand Down Expand Up @@ -1837,7 +1837,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_VERSION = 4.1;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down Expand Up @@ -1900,6 +1900,7 @@
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -1957,6 +1958,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
2 changes: 1 addition & 1 deletion LayoutKitSampleApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = UINavigationController(rootViewController: MenuViewController())
window?.makeKeyAndVisible()
Expand Down
4 changes: 2 additions & 2 deletions LayoutKitSampleApp/Benchmarks/TableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TableViewController<ContentViewType: UIView>: UITableViewController where

init(data: [CellType.DataType]) {
self.data = data
super.init(style: UITableViewStyle.grouped)
super.init(style: UITableView.Style.grouped)
}

required init?(coder aDecoder: NSCoder) {
Expand All @@ -52,7 +52,7 @@ class TableViewController<ContentViewType: UIView>: UITableViewController where
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
return UITableView.automaticDimension
}
}

Expand Down
6 changes: 3 additions & 3 deletions LayoutKitTests/LabelLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class LabelLayoutTests: XCTestCase {
}

func testAttributedLabel() {
let attributedText = NSAttributedString(string: "Hi", attributes: [NSAttributedStringKey.font: UIFont.helvetica(size: 42)])
let attributedText = NSAttributedString(string: "Hi", attributes: [NSAttributedString.Key.font: UIFont.helvetica(size: 42)])
let font = UIFont.helvetica(size: 99)

let arrangement = LabelLayout(attributedText: attributedText, font: font).arrangement()
Expand Down Expand Up @@ -122,7 +122,7 @@ class LabelLayoutTests: XCTestCase {
func testAttributedTextCustomFont() {
#if !os(tvOS) // tvOS doesn't currently support custom fonts
let font = UIFont(name: "Papyrus", size: 20)!
let attributes = [NSAttributedStringKey.font: font]
let attributes = [NSAttributedString.Key.font: font]
let text = NSAttributedString(string: "Hello! 😄😄😄", attributes: attributes)

let arrangement = LabelLayout(attributedText: text).arrangement()
Expand All @@ -136,7 +136,7 @@ class LabelLayoutTests: XCTestCase {
#if !os(tvOS) // tvOS doesn't currently support custom fonts
let font = UIFont(name: "Papyrus", size: 20)!
let text = NSMutableAttributedString(string: "Hello world! 😄😄😄")
text.addAttribute(NSAttributedStringKey.font, value: font, range: NSMakeRange(6, 6))
text.addAttribute(NSAttributedString.Key.font, value: font, range: NSMakeRange(6, 6))

let arrangement = LabelLayout(attributedText: text).arrangement()
let label = UILabel(attributedText: text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ private class TestCollectionView: LayoutAdapterCollectionView, TestableReloadabl
}

fileprivate func verifyHeader(_ section: Int, text: String?, frame: CGRect?, file: StaticString, line: UInt) {
verifySupplementaryView(UICollectionElementKindSectionHeader, section: section, text: text, frame: frame, file: file, line: line)
verifySupplementaryView(UICollectionView.elementKindSectionHeader, section: section, text: text, frame: frame, file: file, line: line)
}

fileprivate func verifyFooter(_ section: Int, text: String?, frame: CGRect?, file: StaticString, line: UInt) {
verifySupplementaryView(UICollectionElementKindSectionFooter, section: section, text: text, frame: frame, file: file, line: line)
verifySupplementaryView(UICollectionView.elementKindSectionFooter, section: section, text: text, frame: frame, file: file, line: line)
}

private func verifySupplementaryView(_ kind: String, section: Int, text: String?, frame: CGRect?, file: StaticString, line: UInt) {
Expand Down
12 changes: 6 additions & 6 deletions LayoutKitTests/ReloadableViewLayoutAdapterTableViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ private class TestTableView: LayoutAdapterTableView, TestableReloadableView {
reloadDataCount += 1
}

fileprivate override func insertRows(at indexPaths: [IndexPath], with animation: UITableViewRowAnimation) {
fileprivate override func insertRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation) {
super.insertRows(at: indexPaths, with: animation)
batchUpdates.insertItems.append(contentsOf: indexPaths)
}

fileprivate override func deleteRows(at indexPaths: [IndexPath], with animation: UITableViewRowAnimation) {
fileprivate override func deleteRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation) {
super.deleteRows(at: indexPaths, with: animation)
batchUpdates.deleteItems.append(contentsOf: indexPaths)
}

fileprivate override func reloadRows(at indexPaths: [IndexPath], with animation: UITableViewRowAnimation) {
fileprivate override func reloadRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation) {
super.reloadRows(at: indexPaths, with: animation)
batchUpdates.reloadItems.append(contentsOf: indexPaths)
}
Expand All @@ -88,17 +88,17 @@ private class TestTableView: LayoutAdapterTableView, TestableReloadableView {
batchUpdates.moveItems.append(ItemMove(from: indexPath, to: newIndexPath))
}

fileprivate override func insertSections(_ sections: IndexSet, with animation: UITableViewRowAnimation) {
fileprivate override func insertSections(_ sections: IndexSet, with animation: UITableView.RowAnimation) {
super.insertSections(sections, with: animation)
batchUpdates.insertSections.formUnion(sections)
}

fileprivate override func reloadSections(_ sections: IndexSet, with animation: UITableViewRowAnimation) {
fileprivate override func reloadSections(_ sections: IndexSet, with animation: UITableView.RowAnimation) {
super.reloadSections(sections, with: animation)
batchUpdates.reloadSections.formUnion(sections)
}

fileprivate override func deleteSections(_ sections: IndexSet, with animation: UITableViewRowAnimation) {
fileprivate override func deleteSections(_ sections: IndexSet, with animation: UITableView.RowAnimation) {
super.deleteSections(sections, with: animation)
batchUpdates.deleteSections.formUnion(sections)
}
Expand Down
6 changes: 3 additions & 3 deletions LayoutKitTests/TextExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ extension Text {
.unattributed("Hello! 😄😄😄"),
.attributed(NSAttributedString(string: "")),
.attributed(NSAttributedString(string: " ")),
.attributed(NSAttributedString(string: "", attributes: [NSAttributedStringKey.font: UIFont.helvetica(size: 42)])),
.attributed(NSAttributedString(string: " ", attributes: [NSAttributedStringKey.font: UIFont.helvetica(size: 42)])),
.attributed(NSAttributedString(string: "", attributes: [NSAttributedString.Key.font: UIFont.helvetica(size: 42)])),
.attributed(NSAttributedString(string: " ", attributes: [NSAttributedString.Key.font: UIFont.helvetica(size: 42)])),
.attributed(NSAttributedString(string: "Hi")),
.attributed(NSAttributedString(string: "Hello world")),
.attributed(NSAttributedString(string: "Hello! 😄😄😄")),
.attributed(NSAttributedString(string: "Hello! 😄😄😄", attributes: [NSAttributedStringKey.font: UIFont.helvetica(size: 42)])),
.attributed(NSAttributedString(string: "Hello! 😄😄😄", attributes: [NSAttributedString.Key.font: UIFont.helvetica(size: 42)])),
]

let fontSizes = 0...20
Expand Down
4 changes: 2 additions & 2 deletions LayoutKitTests/TextViewLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class TextViewLayoutTests: XCTestCase {
let textString = "Hello World\nHello World\nHello World\nHello World\nHello World"
let attributedString1 = NSMutableAttributedString(
string: textString,
attributes: [NSAttributedStringKey.font: UIFont.helvetica(size: 15)])
attributes: [NSAttributedString.Key.font: UIFont.helvetica(size: 15)])
let attributedString2 = NSMutableAttributedString(
string: textString,
attributes: [NSAttributedStringKey.font: UIFont.helvetica(size: 12)])
attributes: [NSAttributedString.Key.font: UIFont.helvetica(size: 12)])
attributedString1.append(attributedString2)
let attributedText = Text.attributed(attributedString1)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Internal/NSAttributedStringExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension NSAttributedString {

/// Returns a new NSAttributedString with a given font and the same attributes.
func with(font: UIFont) -> NSAttributedString {
let fontAttribute = [NSAttributedStringKey.font: font]
let fontAttribute = [NSAttributedString.Key.font: font]
let attributedTextWithFont = NSMutableAttributedString(string: string, attributes: fontAttribute)
let fullRange = NSMakeRange(0, (string as NSString).length)
attributedTextWithFont.beginEditing()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Layouts/ButtonLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public enum ButtonLayoutType {
case infoDark
case contactAdd

public var buttonType: UIButtonType {
public var buttonType: UIButton.ButtonType {
switch (self) {
case .custom:
return .custom
Expand Down
2 changes: 1 addition & 1 deletion Sources/Layouts/TextViewLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private extension Text {
case .attributed(_):
let text = Text.attributed(NSAttributedString(
string: spaceString,
attributes: [NSAttributedStringKey.font: font]))
attributes: [NSAttributedString.Key.font: font]))
size = text.textSize(within: maxSize, font: font)

case .unattributed(_):
Expand Down
2 changes: 1 addition & 1 deletion Sources/Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public enum Text {
if text.isEmpty {
return .zero
}
size = text.boundingRect(with: maxSize, options: options, attributes: [NSAttributedStringKey.font: font], context: nil).size
size = text.boundingRect(with: maxSize, options: options, attributes: [NSAttributedString.Key.font: font], context: nil).size
}
// boundingRect(with:options:attributes:) returns size to a precision of hundredths of a point,
// but UILabel only returns sizes with a point precision of 1/screenDensity.
Expand Down
4 changes: 2 additions & 2 deletions Sources/Views/ReloadableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ extension UICollectionView: ReloadableView {
@objc
open func registerViews(withReuseIdentifier reuseIdentifier: String) {
register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: reuseIdentifier)
register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: reuseIdentifier)
register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: reuseIdentifier)
register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: reuseIdentifier)
}

@objc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ extension ReloadableViewLayoutAdapter: UICollectionViewDataSource {
let view = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: reuseIdentifier, for: indexPath)
let arrangement: LayoutArrangement?
switch kind {
case UICollectionElementKindSectionHeader:
case UICollectionView.elementKindSectionHeader:
arrangement = currentArrangement[indexPath.section].header
case UICollectionElementKindSectionFooter:
case UICollectionView.elementKindSectionFooter:
arrangement = currentArrangement[indexPath.section].footer
default:
arrangement = nil
Expand Down
2 changes: 1 addition & 1 deletion Sources/Views/StackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private struct ViewLayout: ConfigurableLayout {
return Flexibility(horizontal: horizontal, vertical: vertical)
}

private func flexForAxis(_ axis: UILayoutConstraintAxis) -> Flexibility.Flex {
private func flexForAxis(_ axis: NSLayoutConstraint.Axis) -> Flexibility.Flex {
switch view.contentHuggingPriority(for: .horizontal) {
case UILayoutPriority.required:
return nil
Expand Down
4 changes: 2 additions & 2 deletions Tests/cocoapods/ios/LayoutKit-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.Linkedin.LayoutKit-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.1;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -320,7 +320,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.Linkedin.LayoutKit-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.1;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = "com.Linkedin.LayoutKit-macOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.1;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -325,7 +325,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = "com.Linkedin.LayoutKit-macOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.1;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
4 changes: 2 additions & 2 deletions Tests/cocoapods/tvos/LayoutKit-tvOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.linkedin.LayoutKit-tvOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.1;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -316,7 +316,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.linkedin.LayoutKit-tvOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.1;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
20 changes: 11 additions & 9 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ rm -rf $DERIVED_DATA &&
time xcodebuild clean test \
-project LayoutKit.xcodeproj \
-scheme LayoutKit-iOS \
-sdk iphonesimulator11.3 \
-sdk iphonesimulator12.0 \
-derivedDataPath $DERIVED_DATA \
-destination 'platform=iOS Simulator,name=iPhone 6,OS=10.3.1' \
-destination 'platform=iOS Simulator,name=iPhone 6 Plus,OS=10.3.1' \
-destination 'platform=iOS Simulator,name=iPhone 7,OS=11.3' \
-destination 'platform=iOS Simulator,name=iPhone 7 Plus,OS=11.3' \
-disable-concurrent-destination-testing test-without-building \
OTHER_SWIFT_FLAGS='-Xfrontend -debug-time-function-bodies' \
| tee build.log \
| xcpretty &&
Expand All @@ -27,7 +28,7 @@ echo "Run tests on macOS..." &&
time xcodebuild clean test \
-project LayoutKit.xcodeproj \
-scheme LayoutKit-macOS \
-sdk macosx10.13 \
-sdk macosx10.14 \
-derivedDataPath $DERIVED_DATA \
OTHER_SWIFT_FLAGS='-Xfrontend -debug-time-function-bodies' \
| tee build.log \
Expand All @@ -39,9 +40,9 @@ rm -rf $DERIVED_DATA &&
time xcodebuild clean test \
-project LayoutKit.xcodeproj \
-scheme LayoutKit-tvOS \
-sdk appletvsimulator11.3 \
-sdk appletvsimulator12.0 \
-derivedDataPath $DERIVED_DATA \
-destination 'platform=tvOS Simulator,name=Apple TV 1080p,OS=11.0' \
-destination 'platform=tvOS Simulator,name=Apple TV 4K (at 1080p),OS=11.0' \
OTHER_SWIFT_FLAGS='-Xfrontend -debug-time-function-bodies' \
| tee build.log \
| xcpretty &&
Expand All @@ -52,12 +53,13 @@ rm -rf $DERIVED_DATA &&
time xcodebuild clean build \
-project LayoutKit.xcodeproj \
-scheme LayoutKitSampleApp \
-sdk iphonesimulator11.3 \
-sdk iphonesimulator12.0 \
-derivedDataPath $DERIVED_DATA \
-destination 'platform=iOS Simulator,name=iPhone 6,OS=10.3.1' \
-destination 'platform=iOS Simulator,name=iPhone 6 Plus,OS=10.3.1' \
-destination 'platform=iOS Simulator,name=iPhone 7,OS=11.3' \
-destination 'platform=iOS Simulator,name=iPhone 7 Plus,OS=11.3' \
-disable-concurrent-destination-testing \
OTHER_SWIFT_FLAGS='-Xfrontend -debug-time-function-bodies' \
| tee ../build.log \
| xcpretty &&
Expand All @@ -72,7 +74,7 @@ pod install &&
time xcodebuild clean build \
-workspace LayoutKit-iOS.xcworkspace \
-scheme LayoutKit-iOS \
-sdk iphonesimulator11.3 \
-sdk iphonesimulator12.0 \
-derivedDataPath $DERIVED_DATA \
-destination 'platform=iOS Simulator,name=iPhone 7,OS=11.3' \
OTHER_SWIFT_FLAGS='-Xfrontend -debug-time-function-bodies' \
Expand All @@ -88,7 +90,7 @@ pod install &&
time xcodebuild clean build \
-workspace LayoutKit-macOS.xcworkspace \
-scheme LayoutKit-macOS \
-sdk macosx10.13 \
-sdk macosx10.14 \
-derivedDataPath $DERIVED_DATA \
OTHER_SWIFT_FLAGS='-Xfrontend -debug-time-function-bodies' \
| tee ../../../build.log \
Expand All @@ -103,9 +105,9 @@ pod install &&
time xcodebuild clean build \
-workspace LayoutKit-tvOS.xcworkspace \
-scheme LayoutKit-tvOS \
-sdk appletvsimulator11.3 \
-sdk appletvsimulator12.0 \
-derivedDataPath $DERIVED_DATA \
-destination 'platform=tvOS Simulator,name=Apple TV 1080p,OS=11.0' \
-destination 'platform=tvOS Simulator,name=Apple TV 4K (at 1080p),OS=11.0' \
OTHER_SWIFT_FLAGS='-Xfrontend -debug-time-function-bodies' \
| tee ../../../build.log \
| xcpretty &&
Expand Down