Skip to content

Commit

Permalink
moved to swift 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Marunko committed Mar 26, 2019
1 parent 5152395 commit bb3cb69
Show file tree
Hide file tree
Showing 25 changed files with 98 additions and 91 deletions.
4 changes: 2 additions & 2 deletions Dependencies/SWXMLHash/SWXMLHash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ public enum XMLIndexer {
/// All child elements from the currently indexed level
public var children: [XMLIndexer] {
var list = [XMLIndexer]()
for elem in all.flatMap({ $0.element }) {
for elem in all.compactMap({ $0.element }) {
for elem in elem.xmlChildren {
list.append(XMLIndexer(elem))
}
Expand Down Expand Up @@ -817,7 +817,7 @@ public class XMLElement: XMLContent {
var index: Int

var xmlChildren: [XMLElement] {
return children.flatMap { $0 as? XMLElement }
return children.compactMap { $0 as? XMLElement }
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Macaw.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Pod::Spec.new do |s|
s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.12"
s.requires_arc = true
s.swift_version = "4.2"
s.swift_version = "5.0"

s.source_files = [
'Source/**/*.swift'
Expand Down
16 changes: 8 additions & 8 deletions Macaw.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,7 @@
};
buildConfigurationList = 57FCD2661D76EA4600CC0FB6 /* Build configuration list for PBXProject "Macaw" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down Expand Up @@ -1996,7 +1996,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint autocorrect --format\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
shellScript = "if which swiftlint >/dev/null; then\n swiftlint autocorrect --format\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down Expand Up @@ -2331,7 +2331,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = macosx;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
};
name = Debug;
Expand All @@ -2356,7 +2356,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = macosx;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
};
name = Release;
Expand Down Expand Up @@ -2503,7 +2503,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
};
name = Debug;
Expand All @@ -2528,7 +2528,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
};
name = Release;
Expand All @@ -2550,7 +2550,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
VALID_ARCHS = "x86_64 i386";
};
Expand All @@ -2573,7 +2573,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
VALID_ARCHS = "x86_64 i386";
};
Expand Down
5 changes: 3 additions & 2 deletions Source/animation/AnimationImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ class BasicAnimation: Animation {

// MARK: - Hashable
extension BasicAnimation: Hashable {
public var hashValue: Int {
return ID.hashValue

func hash(into hasher: inout Hasher) {
hasher.combine(ID)
}

public static func == (lhs: BasicAnimation, rhs: BasicAnimation) -> Bool {
Expand Down
2 changes: 1 addition & 1 deletion Source/animation/types/AnimationSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal class AnimationSequence: BasicAnimation {
}

public extension Sequence where Iterator.Element: Animation {
public func sequence(delay: Double = 0.0) -> Animation {
func sequence(delay: Double = 0.0) -> Animation {

var sequence = [BasicAnimation]()
self.forEach { animation in
Expand Down
2 changes: 1 addition & 1 deletion Source/animation/types/CombineAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal class CombineAnimation: BasicAnimation {
}

public extension Sequence where Iterator.Element: Animation {
public func combine(delay: Double = 0.0, node: Node? = .none, toNodes: [Node] = []) -> Animation {
func combine(delay: Double = 0.0, node: Node? = .none, toNodes: [Node] = []) -> Animation {

var toCombine = [BasicAnimation]()
self.forEach { animation in
Expand Down
12 changes: 6 additions & 6 deletions Source/animation/types/ContentsAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,32 @@ internal class ContentsAnimation: AnimationImpl<[Node]> {

public extension AnimatableVariable where T: ContentsInterpolation {

public func animation(_ f: @escaping (Double) -> [Node]) -> Animation {
func animation(_ f: @escaping (Double) -> [Node]) -> Animation {
let group = node! as! Group
return ContentsAnimation(animatedGroup: group, valueFunc: f, animationDuration: 1.0, delay: 0.0, autostart: false)
}

public func animation(_ f: @escaping ((Double) -> [Node]), during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(_ f: @escaping ((Double) -> [Node]), during: Double = 1.0, delay: Double = 0.0) -> Animation {
let group = node! as! Group
return ContentsAnimation(animatedGroup: group, valueFunc: f, animationDuration: during, delay: delay, autostart: false)
}

public func animation(during: Double = 1.0, delay: Double = 0.0, _ f: @escaping ((Double) -> [Node])) -> Animation {
func animation(during: Double = 1.0, delay: Double = 0.0, _ f: @escaping ((Double) -> [Node])) -> Animation {
let group = node! as! Group
return ContentsAnimation(animatedGroup: group, valueFunc: f, animationDuration: during, delay: delay, autostart: false)
}

public func animate(_ f: @escaping (Double) -> [Node]) {
func animate(_ f: @escaping (Double) -> [Node]) {
let group = node! as! Group
_ = ContentsAnimation(animatedGroup: group, valueFunc: f, animationDuration: 1.0, delay: 0.0, autostart: true)
}

public func animate(_ f: @escaping ((Double) -> [Node]), during: Double = 1.0, delay: Double = 0.0) {
func animate(_ f: @escaping ((Double) -> [Node]), during: Double = 1.0, delay: Double = 0.0) {
let group = node! as! Group
_ = ContentsAnimation(animatedGroup: group, valueFunc: f, animationDuration: during, delay: delay, autostart: true)
}

public func animate(during: Double = 1.0, delay: Double = 0.0, _ f: @escaping ((Double) -> [Node])) {
func animate(during: Double = 1.0, delay: Double = 0.0, _ f: @escaping ((Double) -> [Node])) {
let group = node! as! Group
_ = ContentsAnimation(animatedGroup: group, valueFunc: f, animationDuration: during, delay: delay, autostart: true)
}
Expand Down
14 changes: 7 additions & 7 deletions Source/animation/types/MorphingAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ class MorphingAnimation: AnimationImpl<Locus> {
public typealias MorphingAnimationDescription = AnimationDescription<Locus>

public extension AnimatableVariable where T: LocusInterpolation {
public func animate(_ desc: MorphingAnimationDescription) {
func animate(_ desc: MorphingAnimationDescription) {
_ = MorphingAnimation(animatedNode: node as! Shape, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: true)
}

public func animation(_ desc: MorphingAnimationDescription) -> Animation {
func animation(_ desc: MorphingAnimationDescription) -> Animation {
return MorphingAnimation(animatedNode: node as! Shape, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: false)
}

public func animate(from: Locus? = nil, to: Locus, during: Double = 1.0, delay: Double = 0.0) {
func animate(from: Locus? = nil, to: Locus, during: Double = 1.0, delay: Double = 0.0) {
self.animate(((from ?? (node as! Shape).form) >> to).t(during, delay: delay))
}

public func animation(from: Locus? = nil, to: Locus, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(from: Locus? = nil, to: Locus, during: Double = 1.0, delay: Double = 0.0) -> Animation {
if let safeFrom = from {
return self.animation((safeFrom >> to).t(during, delay: delay))
}
Expand All @@ -67,7 +67,7 @@ public extension AnimatableVariable where T: LocusInterpolation {
return MorphingAnimation(animatedNode: self.node as! Shape, factory: factory, animationDuration: during, delay: delay)
}

public func animation(_ f: @escaping (Double) -> Locus, during: Double, delay: Double = 0.0) -> Animation {
func animation(_ f: @escaping (Double) -> Locus, during: Double, delay: Double = 0.0) -> Animation {
return MorphingAnimation(animatedNode: node as! Shape, valueFunc: f, animationDuration: during, delay: delay)
}

Expand All @@ -76,7 +76,7 @@ public extension AnimatableVariable where T: LocusInterpolation {
// MARK: - Group

public extension AnimatableVariable where T: ContentsInterpolation {
public func animation(from: Group? = nil, to: [Node], during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(from: Group? = nil, to: [Node], during: Double = 1.0, delay: Double = 0.0) -> Animation {
var fromNode = node as! Group
if let passedFromNode = from {
fromNode = passedFromNode
Expand All @@ -85,7 +85,7 @@ public extension AnimatableVariable where T: ContentsInterpolation {
return CombineAnimation(animations: [], during: during, node: fromNode, toNodes: to)
}

public func animate(from: Group? = nil, to: [Node], during: Double = 1.0, delay: Double = 0.0) {
func animate(from: Group? = nil, to: [Node], during: Double = 1.0, delay: Double = 0.0) {
animation(from: from, to: to, during: during, delay: delay).play()
}
}
10 changes: 5 additions & 5 deletions Source/animation/types/OpacityAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ internal class OpacityAnimation: AnimationImpl<Double> {
public typealias OpacityAnimationDescription = AnimationDescription<Double>

public extension AnimatableVariable where T: DoubleInterpolation {
public func animate(_ desc: OpacityAnimationDescription) {
func animate(_ desc: OpacityAnimationDescription) {
_ = OpacityAnimation(animatedNode: node!, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: true)
}

public func animation(_ desc: OpacityAnimationDescription) -> Animation {
func animation(_ desc: OpacityAnimationDescription) -> Animation {
return OpacityAnimation(animatedNode: node!, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: false)
}

public func animate(from: Double? = nil, to: Double, during: Double = 1.0, delay: Double = 0.0) {
func animate(from: Double? = nil, to: Double, during: Double = 1.0, delay: Double = 0.0) {
self.animate(((from ?? node!.opacity) >> to).t(during, delay: delay))
}

public func animation(from: Double? = nil, to: Double, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(from: Double? = nil, to: Double, during: Double = 1.0, delay: Double = 0.0) -> Animation {
if let safeFrom = from {
return self.animation((safeFrom >> to).t(during, delay: delay))
}
Expand All @@ -71,7 +71,7 @@ public extension AnimatableVariable where T: DoubleInterpolation {
return OpacityAnimation(animatedNode: self.node!, factory: factory, animationDuration: during, delay: delay)
}

public func animation(_ f: @escaping ((Double) -> Double), during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(_ f: @escaping ((Double) -> Double), during: Double = 1.0, delay: Double = 0.0) -> Animation {
return OpacityAnimation(animatedNode: node!, valueFunc: f, animationDuration: during, delay: delay)
}

Expand Down
8 changes: 4 additions & 4 deletions Source/animation/types/ShapeAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ShapeAnimation: AnimationImpl<Shape> {
}

public extension AnimatableVariable {
public func animate<T: Stroke>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) {
func animate<T: Stroke>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) {
let shape = node as! Shape

var safeFrom = from
Expand All @@ -89,7 +89,7 @@ public extension AnimatableVariable {
_ = ShapeAnimation(animatedNode: shape, finalValue: finalShape, animationDuration: during, delay: delay, autostart: true)
}

public func animation<T: Stroke>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation<T: Stroke>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) -> Animation {
let shape = node as! Shape

var safeFrom = from
Expand All @@ -111,7 +111,7 @@ public extension AnimatableVariable {
}

public extension AnimatableVariable {
public func animate<T: Fill>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) {
func animate<T: Fill>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) {
let shape = node as! Shape

var safeFrom = from
Expand All @@ -131,7 +131,7 @@ public extension AnimatableVariable {
_ = ShapeAnimation(animatedNode: shape, finalValue: finalShape, animationDuration: during, delay: delay, autostart: true)
}

public func animation<T: Fill>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation<T: Fill>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) -> Animation {
let shape = node as! Shape

var safeFrom = from
Expand Down
18 changes: 9 additions & 9 deletions Source/animation/types/TransformAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,29 @@ internal class TransformAnimation: AnimationImpl<Transform> {
public typealias TransformAnimationDescription = AnimationDescription<Transform>

public extension AnimatableVariable where T: TransformInterpolation {
public func animate(_ desc: TransformAnimationDescription) {
func animate(_ desc: TransformAnimationDescription) {
_ = TransformAnimation(animatedNode: node!, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: true)
}

public func animation(_ desc: TransformAnimationDescription) -> Animation {
func animation(_ desc: TransformAnimationDescription) -> Animation {
return TransformAnimation(animatedNode: node!, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: false)
}

public func animate(from: Transform? = nil, to: Transform, during: Double = 1.0, delay: Double = 0.0) {
func animate(from: Transform? = nil, to: Transform, during: Double = 1.0, delay: Double = 0.0) {
self.animate(((from ?? node!.place) >> to).t(during, delay: delay))
}

public func animate(angle: Double, x: Double? = .none, y: Double? = .none, during: Double = 1.0, delay: Double = 0.0) {
func animate(angle: Double, x: Double? = .none, y: Double? = .none, during: Double = 1.0, delay: Double = 0.0) {
let animation = self.animation(angle: angle, x: x, y: y, during: during, delay: delay)
animation.play()
}

public func animate(along path: Path, during: Double = 1.0, delay: Double = 0.0) {
func animate(along path: Path, during: Double = 1.0, delay: Double = 0.0) {
let animation = self.animation(along: path, during: during, delay: delay)
animation.play()
}

public func animation(from: Transform? = nil, to: Transform, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(from: Transform? = nil, to: Transform, during: Double = 1.0, delay: Double = 0.0) -> Animation {
if let safeFrom = from {
return self.animation((safeFrom >> to).t(during, delay: delay))
}
Expand All @@ -98,11 +98,11 @@ public extension AnimatableVariable where T: TransformInterpolation {
return TransformAnimation(animatedNode: self.node!, factory: factory, animationDuration: during, delay: delay)
}

public func animation(_ f: @escaping ((Double) -> Transform), during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(_ f: @escaping ((Double) -> Transform), during: Double = 1.0, delay: Double = 0.0) -> Animation {
return TransformAnimation(animatedNode: node!, valueFunc: f, animationDuration: during, delay: delay)
}

public func animation(angle: Double, x: Double? = .none, y: Double? = .none, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(angle: Double, x: Double? = .none, y: Double? = .none, during: Double = 1.0, delay: Double = 0.0) -> Animation {
let bounds = node!.bounds!

let factory = { () -> (Double) -> Transform in { t in
Expand Down Expand Up @@ -130,7 +130,7 @@ public extension AnimatableVariable where T: TransformInterpolation {
return TransformAnimation(animatedNode: self.node!, factory: factory, animationDuration: during, delay: delay)
}

public func animation(along path: Path, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(along path: Path, during: Double = 1.0, delay: Double = 0.0) -> Animation {

let factory = { () -> (Double) -> Transform in { (t: Double) in Transform.identity }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// TODO: Implement better hash

extension Node: Hashable {
public var hashValue: Int {
return Unmanaged.passUnretained(self).toOpaque().hashValue
public func hash(into hasher: inout Hasher) {
hasher.combine(Unmanaged.passUnretained(self).toOpaque())
}
}

Expand All @@ -11,8 +11,8 @@ public func == (lhs: Node, rhs: Node) -> Bool {
}

extension NodeRenderer: Hashable {
public var hashValue: Int {
return Unmanaged.passUnretained(self).toOpaque().hashValue
func hash(into hasher: inout Hasher) {
hasher.combine(Unmanaged.passUnretained(self).toOpaque())
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
extension Transform: Hashable {
public var hashValue: Int {
return m11.hashValue ^
m12.hashValue ^
m21.hashValue ^
m22.hashValue ^
dx.hashValue ^
dy.hashValue
public func hash(into hasher: inout Hasher) {
hasher.combine(m11)
hasher.combine(m12)
hasher.combine(m21)
hasher.combine(m22)
hasher.combine(dx)
hasher.combine(dy)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/bindings/Variable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ open class Variable<T> {
let handler = ChangeHandler<T>(f)
handlers.append(handler)
return Disposable { [weak self, unowned handler] in
guard let index = self?.handlers.index(of: handler) else {
guard let index = self?.handlers.firstIndex(of: handler) else {
return
}

Expand Down
Loading

0 comments on commit bb3cb69

Please sign in to comment.