Skip to content

Commit

Permalink
Merge pull request #54 from guidomb/swift-4-migration
Browse files Browse the repository at this point in the history
Migrate Portal to use Swift 4.
  • Loading branch information
Guido Marucci Blas committed Oct 15, 2017
2 parents 877f68c + 797c93d commit dbe99b2
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Example/Views/CustomComponent/CustomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class CustomView: UIView {
redView.addGestureRecognizer(gestureRecognizer)
}

func tapped() {
@objc func tapped() {
onTap?()
}

Expand Down
23 changes: 15 additions & 8 deletions Portal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -832,12 +832,13 @@
9D0F333C1E78F81800C65BED = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 7SMPV9L38V;
LastSwiftMigration = 0820;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
9D0F33451E78F81800C65BED = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 7SMPV9L38V;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
TestTargetID = 9D7824071E92B9C7004455B1;
};
Expand All @@ -849,7 +850,7 @@
9D7824071E92B9C7004455B1 = {
CreatedOnToolsVersion = 8.3;
DevelopmentTeam = 7SMPV9L38V;
LastSwiftMigration = 0830;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -1238,7 +1239,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -1260,7 +1262,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.syrmo.Portal;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -1277,7 +1280,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.syrmo.PortalTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PortalExample.app/PortalExample";
};
name = Debug;
Expand All @@ -1295,7 +1299,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.syrmo.PortalTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PortalExample.app/PortalExample";
};
name = Release;
Expand Down Expand Up @@ -1355,7 +1360,8 @@
PRODUCT_BUNDLE_IDENTIFIER = me.guidomb.Portal.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -1373,7 +1379,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = me.guidomb.Portal.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
4 changes: 3 additions & 1 deletion Portal/Middlewares/StatePersistor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public final class StatePersistor<

private let dispatchQueue = DispatchQueue(label: "com.Portal.StatePersistor")

public init(serializer: StatePersistorSerializerType, shouldPersist: @escaping TransitionFilter = { _ in true }) {
public init(
serializer: StatePersistorSerializerType,
shouldPersist: @escaping TransitionFilter = { _, _, _ in true }) {
self.serializer = serializer
self.shouldPersist = shouldPersist
}
Expand Down
2 changes: 1 addition & 1 deletion Portal/View/Components/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct ButtonProperties<MessageType>: AutoPropertyDiffable {
// sourcery: skipDiff
public var onTap: MessageType?

fileprivate init(
public init(
text: String? = .none,
isActive: Bool = false,
icon: Image? = .none,
Expand Down
2 changes: 1 addition & 1 deletion Portal/View/Components/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public struct CollectionStyleSheet: AutoPropertyDiffable {
}

public func collectionStyleSheet(
configure: (inout BaseStyleSheet, inout CollectionStyleSheet) -> Void = { _ in })
configure: (inout BaseStyleSheet, inout CollectionStyleSheet) -> Void = { _, _ in })
-> StyleSheet<CollectionStyleSheet> {
var base = BaseStyleSheet()
var component = CollectionStyleSheet()
Expand Down
6 changes: 3 additions & 3 deletions Portal/View/Components/Label.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct LabelProperties: AutoPropertyDiffable {
public let text: String
public let textAfterLayout: String?

fileprivate init(text: String, textAfterLayout: String?) {
public init(text: String, textAfterLayout: String?) {
self.text = text
self.textAfterLayout = textAfterLayout
}
Expand Down Expand Up @@ -44,7 +44,7 @@ public func properties(

public struct LabelStyleSheet: AutoPropertyDiffable {

static let `default` = StyleSheet<LabelStyleSheet>(component: LabelStyleSheet())
public static let `default` = StyleSheet<LabelStyleSheet>(component: LabelStyleSheet())

public var textColor: Color
public var textFont: Font
Expand Down Expand Up @@ -74,7 +74,7 @@ public struct LabelStyleSheet: AutoPropertyDiffable {
}

public func labelStyleSheet(
configure: (inout BaseStyleSheet, inout LabelStyleSheet) -> Void = { _ in }) -> StyleSheet<LabelStyleSheet> {
configure: (inout BaseStyleSheet, inout LabelStyleSheet) -> Void = { _, _ in }) -> StyleSheet<LabelStyleSheet> {
var base = BaseStyleSheet()
var component = LabelStyleSheet()
configure(&base, &component)
Expand Down
2 changes: 1 addition & 1 deletion Portal/View/Components/NavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public struct NavigationBarStyleSheet {
}

public func navigationBarStyleSheet(
configure: (inout BaseStyleSheet, inout NavigationBarStyleSheet) -> Void = { _ in }
configure: (inout BaseStyleSheet, inout NavigationBarStyleSheet) -> Void = { _, _ in }
) -> StyleSheet<NavigationBarStyleSheet> {
var base = BaseStyleSheet()
var component = NavigationBarStyleSheet()
Expand Down
2 changes: 1 addition & 1 deletion Portal/View/Components/Progress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public struct ProgressCounter {

internal static let initial = ProgressCounter()
public static let initial = ProgressCounter()

// sourcery: ignoreInChangeSet
public var partial: UInt
Expand Down
6 changes: 3 additions & 3 deletions Portal/View/Components/Table.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public struct TableProperties<MessageType>: AutoPropertyDiffable {
// sourcery: skipDiff
public var refresh: RefreshProperties<MessageType>?

fileprivate init(
public init(
items: [TableItemProperties<MessageType>] = [],
showsVerticalScrollIndicator: Bool = true,
showsHorizontalScrollIndicator: Bool = true,
Expand Down Expand Up @@ -58,7 +58,7 @@ public struct TableItemProperties<MessageType> {
public let selectionStyle: TableItemSelectionStyle
public let renderer: Renderer

fileprivate init(
public init(
height: UInt,
onTap: MessageType?,
selectionStyle: TableItemSelectionStyle,
Expand Down Expand Up @@ -155,7 +155,7 @@ public struct TableStyleSheet: AutoPropertyDiffable {
}

public func tableStyleSheet(
configure: (inout BaseStyleSheet, inout TableStyleSheet) -> Void = { _ in }) -> StyleSheet<TableStyleSheet> {
configure: (inout BaseStyleSheet, inout TableStyleSheet) -> Void = { _, _ in }) -> StyleSheet<TableStyleSheet> {
var base = BaseStyleSheet()
var component = TableStyleSheet()
configure(&base, &component)
Expand Down
8 changes: 4 additions & 4 deletions Portal/View/Components/TextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct TextFieldProperties<MessageType>: AutoPropertyDiffable {
// sourcery: skipDiff
public var onEvents: TextFieldEvents<MessageType> = TextFieldEvents()

fileprivate init(
public init(
text: String? = .none,
placeholder: String? = .none,
isSecureTextEntry: Bool = false,
Expand Down Expand Up @@ -48,7 +48,7 @@ public struct TextFieldEvents<MessageType> {
public var onEditingChanged: ((String) -> MessageType)?
public var onEditingEnd: ((String) -> MessageType)?

fileprivate init(
public init(
onEditingBegin: ((String) -> MessageType)? = .none,
onEditingChanged: ((String) -> MessageType)? = .none,
onEditingEnd: ((String) -> MessageType)? = .none
Expand Down Expand Up @@ -95,7 +95,7 @@ public func textFieldEvents<MessageType>(

public struct TextFieldStyleSheet: AutoPropertyDiffable {

static let `default` = StyleSheet<TextFieldStyleSheet>(component: TextFieldStyleSheet())
public static let `default` = StyleSheet<TextFieldStyleSheet>(component: TextFieldStyleSheet())

public var textColor: Color
public var textFont: Font
Expand All @@ -115,7 +115,7 @@ public struct TextFieldStyleSheet: AutoPropertyDiffable {
}

public func textFieldStyleSheet(
configure: (inout BaseStyleSheet, inout TextFieldStyleSheet) -> Void = { _ in }
configure: (inout BaseStyleSheet, inout TextFieldStyleSheet) -> Void = { _, _ in }
) -> StyleSheet<TextFieldStyleSheet> {
var base = BaseStyleSheet()
var component = TextFieldStyleSheet()
Expand Down
6 changes: 3 additions & 3 deletions Portal/View/Components/TextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public struct TextViewProperties: AutoPropertyDiffable {
public var isScrollEnabled: Bool
public var isEditable: Bool

fileprivate init(text: Text = .regular(""), isScrollEnabled: Bool = false, isEditable: Bool = false) {
public init(text: Text = .regular(""), isScrollEnabled: Bool = false, isEditable: Bool = false) {
self.text = text
self.isScrollEnabled = isScrollEnabled
self.isEditable = isEditable
Expand All @@ -47,7 +47,7 @@ public func properties(

public struct TextViewStyleSheet: AutoPropertyDiffable {

static let `default` = StyleSheet<TextViewStyleSheet>(component: TextViewStyleSheet())
public static let `default` = StyleSheet<TextViewStyleSheet>(component: TextViewStyleSheet())

public var textColor: Color
public var textFont: Font
Expand All @@ -68,7 +68,7 @@ public struct TextViewStyleSheet: AutoPropertyDiffable {
}

public func textViewStyleSheet(
configure: (inout BaseStyleSheet, inout TextViewStyleSheet) -> Void = { _ in }
configure: (inout BaseStyleSheet, inout TextViewStyleSheet) -> Void = { _, _ in }
) -> StyleSheet<TextViewStyleSheet> {
var base = BaseStyleSheet()
var component = TextViewStyleSheet()
Expand Down
10 changes: 7 additions & 3 deletions Portal/View/LayoutEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ public protocol LayoutEngine {

}

internal struct YogaLayoutEngine: LayoutEngine {
public struct YogaLayoutEngine: LayoutEngine {

public init() {

}

func executeLayout(for view: UIView) {
public func executeLayout(for view: UIView) {
view.yoga.isEnabled = true
view.yoga.width = view.bounds.size.width
view.yoga.height = view.bounds.size.height
view.yoga.applyLayout(preservingOrigin: true)
}

// swiftlint:disable cyclomatic_complexity
func apply(changeSet: [Layout.Property], to view: UIView) {
public func apply(changeSet: [Layout.Property], to view: UIView) {
view.yoga.isEnabled = true

for property in changeSet {
Expand Down
3 changes: 1 addition & 2 deletions Portal/View/UIKit/MessageDispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ internal final class MessageDispatcher<MessageType>: NSObject {
self.sender2Message = sender2Message
}

@objc
internal func dispatch(sender: Any) {
@objc internal func dispatch(sender: Any) {
guard let message = sender2Message(sender) else { return }
mailbox.dispatch(message: message)
}
Expand Down
6 changes: 3 additions & 3 deletions Portal/View/UIKit/Renderers/NavigationBarTitleRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ extension UINavigationBar {
self.barTintColor = style.base.backgroundColor.asUIColor
self.tintColor = style.component.tintColor.asUIColor
self.isTranslucent = style.component.isTranslucent
var titleTextAttributes: [String : Any] = [
NSForegroundColorAttributeName: style.component.titleTextColor.asUIColor
var titleTextAttributes: [NSAttributedStringKey : Any] = [
.foregroundColor: style.component.titleTextColor.asUIColor
]
let font = style.component.titleTextFont
let fontSize = style.component.titleTextSize
font.uiFont(withSize: fontSize) |> { titleTextAttributes[NSFontAttributeName] = $0 }
font.uiFont(withSize: fontSize) |> { titleTextAttributes[.font] = $0 }
self.titleTextAttributes = titleTextAttributes
}

Expand Down
12 changes: 6 additions & 6 deletions Portal/View/UIKit/Renderers/SegmentedRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ fileprivate extension UISegmentedControl {
}

fileprivate func apply(changeSet: [SegmentedStyleSheet.Property]) {
let attributes = titleTextAttributes(for: .normal) as? [String : Any]
let font = attributes?[NSFontAttributeName] as? UIFont
let color = attributes?[NSForegroundColorAttributeName] as? UIColor
let attributes = titleTextAttributes(for: .normal) as? [NSAttributedStringKey : Any]
let font = attributes?[.font] as? UIFont
let color = attributes?[.foregroundColor] as? UIColor

var fontName: String? = font?.fontName
var fontSize: CGFloat? = font?.pointSize
Expand All @@ -85,11 +85,11 @@ fileprivate extension UISegmentedControl {
}

fileprivate func setFont(name: String?, size: CGFloat?, color: UIColor?) {
var dictionary = [String: Any]()
var dictionary = [NSAttributedStringKey: Any]()
let font = UIFont(name: name ?? UIFont.systemFont(ofSize: 15).fontName,
size: size ?? CGFloat(defaultSegmentedFontSize))
color |> { dictionary[NSForegroundColorAttributeName] = $0 }
font |> { dictionary[NSFontAttributeName] = $0 }
color |> { dictionary[.foregroundColor] = $0 }
font |> { dictionary[.font] = $0 }
setTitleTextAttributes(dictionary, for: .normal)
}

Expand Down
2 changes: 1 addition & 1 deletion Portal/View/UIKit/UIKitRenderable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extension String {

func maximumFontSize(forWidth width: CGFloat, font: UIFont) -> CGFloat {
let text = self as NSString
let minimumBoundingRect = text.size(attributes: [NSFontAttributeName: font])
let minimumBoundingRect = text.size(withAttributes: [.font: font])
return width * font.pointSize / minimumBoundingRect.width
}

Expand Down
4 changes: 2 additions & 2 deletions PortalTests/SegmentedRendererSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class SegmentedRendererSpec: QuickSpec {
_ = segmented.apply(changeSet: changeSet, layoutEngine: layoutEngine)

let attributes = segmented.titleTextAttributes(for: .normal)!
let color = attributes[NSForegroundColorAttributeName] as! UIColor
let color = attributes[NSAttributedStringKey.foregroundColor] as! UIColor
expect(color).to(equal(UIColor.blue))
}

Expand All @@ -140,7 +140,7 @@ class SegmentedRendererSpec: QuickSpec {
_ = segmented.apply(changeSet: changeSet, layoutEngine: layoutEngine)

let attributes = segmented.titleTextAttributes(for: .normal)!
let font = attributes[NSFontAttributeName] as! UIFont
let font = attributes[NSAttributedStringKey.font] as! UIFont
expect(font).to(equal(UIFont(name: "Helvetica", size: 15)))
}

Expand Down

0 comments on commit dbe99b2

Please sign in to comment.