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

Commit

Permalink
Added support for swift 5
Browse files Browse the repository at this point in the history
  • Loading branch information
li-svartak authored and pa1-linkedin committed Jun 4, 2019
1 parent c77e9bc commit 642d828
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1
5.0
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.2
script: sh build.sh /tmp/LayoutKit
after_success:
- bash <(curl -s https://codecov.io/bash) -D /tmp/LayoutKit
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ rootView.backgroundColor = .white
let textString = "Hello World\nHello World\nHello World\nHello World\nHello World\n"
let attributedString1 = NSMutableAttributedString(
string: textString,
attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 15)])
attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 15)])
let attributedString2 = NSMutableAttributedString(
string: textString,
attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 12)])
attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12)])
attributedString1.append(attributedString2)
let attributedText = Text.attributed(attributedString1)

Expand Down
18 changes: 12 additions & 6 deletions LayoutKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1160,16 +1160,17 @@
TargetAttributes = {
0B2D09AF1D8735E1007E487C = {
CreatedOnToolsVersion = 8.0;
LastSwiftMigration = 0800;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
0BCB755E1D8720110065E02A = {
CreatedOnToolsVersion = 8.0;
LastSwiftMigration = 0800;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
0BCB75671D8720110065E02A = {
CreatedOnToolsVersion = 8.0;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
0BCB757B1D8721370065E02A = {
Expand All @@ -1190,18 +1191,21 @@
};
0BCB75B51D8723B30065E02A = {
CreatedOnToolsVersion = 8.0;
LastSwiftMigration = 0800;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
7EEA2AB5201D18F20077A088 = {
CreatedOnToolsVersion = 9.2;
ProvisioningStyle = Automatic;
};
7EECD00E2053916C003DC4B1 = {
LastSwiftMigration = 1020;
};
};
};
buildConfigurationList = 0BCB75571D871FC40065E02A /* Build configuration list for PBXProject "LayoutKit" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down Expand Up @@ -1730,6 +1734,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -1777,6 +1782,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand Down Expand Up @@ -1812,7 +1818,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
SWIFT_VERSION = 4.1;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand Down Expand Up @@ -1845,7 +1851,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_VERSION = 4.1;
SWIFT_VERSION = 5.0;
};
name = Release;
};
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/ConfigurableLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public protocol ConfigurableLayout: Layout {

// Implement `configure(baseViewType:)` from `Layout`.
public extension ConfigurableLayout {
public func configure(baseTypeView: View) {
func configure(baseTypeView: View) {
guard let view = baseTypeView as? ConfigurableView else {
assertionFailure("Expected baseTypeView \(baseTypeView) to be of type \(ConfigurableView.self) but it was of type \(type(of: baseTypeView))")
return
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/ObjCSupport/Builders/LOKButtonLayoutBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@class LOKButtonLayout;

typedef NS_ENUM(NSInteger, LOKButtonLayoutType) {
typedef NS_CLOSED_ENUM(NSInteger, LOKButtonLayoutType) {
LOKButtonLayoutTypeCustom,
LOKButtonLayoutTypeSystem,
LOKButtonLayoutTypeDetailDisclosure,
Expand Down
4 changes: 2 additions & 2 deletions Sources/ObjCSupport/Builders/LOKStackLayoutBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "LOKLayoutBuilder.h"

typedef NS_ENUM(NSInteger, LOKStackLayoutDistribution) {
typedef NS_CLOSED_ENUM(NSInteger, LOKStackLayoutDistribution) {
LOKStackLayoutDistributionDefault,
LOKStackLayoutDistributionLeading,
LOKStackLayoutDistributionTrailing,
Expand All @@ -18,7 +18,7 @@ typedef NS_ENUM(NSInteger, LOKStackLayoutDistribution) {
LOKStackLayoutDistributionFillFlexing
};

typedef NS_ENUM(NSInteger, LOKAxis) {
typedef NS_CLOSED_ENUM(NSInteger, LOKAxis) {
LOKAxisVertical,
LOKAxisHorizontal
};
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
2 changes: 2 additions & 0 deletions Sources/UIKitSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ extension UIView {
return .leftToRight
case .rightToLeft:
return .rightToLeft
@unknown default:
return .leftToRight
}
} else {
#if LAYOUTKIT_EXTENSION_DEFAULT_RIGHT_TO_LEFT
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
Loading

0 comments on commit 642d828

Please sign in to comment.