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

Resolve Xcode 9 build failures #123

Merged
merged 3 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
33 changes: 33 additions & 0 deletions src/common/DispatchTimeIntervalToSeconds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,38 @@ import CoreGraphics
extension DispatchTimeInterval {
func toSeconds() -> CGFloat {
let seconds: CGFloat

// `.never` was introduced in the latest SDK. In order to support both Xcode 8 and 9 we have to
// implement the `case .never` while not implementing it on Xcode 8. Unfortunately, `#if swift`
// statements placed inside of switch statements can't build, so we're stuck duplicating the
// switch statement.
//
// If we try to write the code like so:
//
// #if swift(>=3.2)
// case .never:
// seconds = CGFloat.infinity
// #endif
//
// We get the following errors:
//
// Extraneous '.' in enum 'case' declaration
// 'case' label can only appear inside a 'switch' statement

#if swift(>=3.2)
switch self {
case let .seconds(arg):
seconds = CGFloat(arg)
case let .milliseconds(arg):
seconds = CGFloat(arg) / 1000.0
case let .microseconds(arg):
seconds = CGFloat(arg) / 1000000.0
case let .nanoseconds(arg):
seconds = CGFloat(arg) / 1000000000.0
case .never:
seconds = CGFloat.infinity
}
#else
switch self {
case let .seconds(arg):
seconds = CGFloat(arg)
Expand All @@ -30,6 +62,7 @@ extension DispatchTimeInterval {
case let .nanoseconds(arg):
seconds = CGFloat(arg) / 1000000000.0
}
#endif
return seconds
}
}
4 changes: 2 additions & 2 deletions src/interactions/Spring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public let defaultSpringMass: CGFloat = 1

T-value constraints may be applied to this interaction.
*/
public class Spring<T>: Interaction, Togglable, Stateful where T: Zeroable, T: Subtractable {
public class Spring<T>: Interaction, Togglable, Stateful where T: ZeroableAndSubtractable {
/**
Creates a spring with a given threshold and system.

Expand Down Expand Up @@ -138,7 +138,7 @@ public class Spring<T>: Interaction, Togglable, Stateful where T: Zeroable, T: S
private var activeSprings = Set<SpringShadow<T>>()
}

public struct SpringShadow<T>: Hashable where T: Zeroable, T: Subtractable {
public struct SpringShadow<T>: Hashable where T: ZeroableAndSubtractable {
public let enabled: ReactiveProperty<Bool>
public let state = createProperty(withInitialValue: MotionState.atRest)
public let initialValue: ReactiveProperty<T>
Expand Down
2 changes: 1 addition & 1 deletion src/interactions/TransitionSpring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public let defaultTransitionSpringSuggestedDuration: CGFloat = 0.5

T-value constraints may be applied to this interaction.
*/
public final class TransitionSpring<T>: Spring<T> where T: Zeroable, T: Subtractable {
public final class TransitionSpring<T>: Spring<T> where T: ZeroableAndSubtractable {

/**
The destination when the transition is moving backward.
Expand Down
30 changes: 30 additions & 0 deletions src/protocols/ZeroableAndSubtractable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright 2016-present The Material Motion Authors. All Rights Reserved.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the copyright to 2017.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation
import UIKit

extension CGPoint: ZeroableAndSubtractable {
}

extension CGSize: ZeroableAndSubtractable {
}

extension CGRect: ZeroableAndSubtractable {
}

extension CGFloat: ZeroableAndSubtractable {
}
2 changes: 1 addition & 1 deletion src/systems/coreAnimationSpringToStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import UIKit

Only works with Subtractable types due to use of additive animations.
*/
public func coreAnimation<T>(_ spring: SpringShadow<T>) -> (MotionObservable<T>) where T: Subtractable {
public func coreAnimation<T>(_ spring: SpringShadow<T>) -> (MotionObservable<T>) {
let initialVelocityStream = spring.initialVelocity.asStream()
return MotionObservable { observer in
var animationKeys: [String] = []
Expand Down