Skip to content

Commit

Permalink
Update syntax with swift 3.0
Browse files Browse the repository at this point in the history
update method parameter names
  • Loading branch information
modzelewski committed Oct 24, 2016
1 parent 916f8d2 commit d441a23
Show file tree
Hide file tree
Showing 30 changed files with 186 additions and 184 deletions.
16 changes: 8 additions & 8 deletions Sources/extensions/Tween+Double.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
public extension Double {
public func trxTo(_ to: Double,
time: TimeInterval = 0.3,
delay: TimeInterval = 0,
ease: @escaping Ease.TimingFunction = Ease.Quad.easeOut,
key: String? = nil,
onStart: StartClosure? = nil,
onComplete: CompletionClosure? = nil,
onUpdate: @escaping Tween<Double>.UpdateClosure
public func trx(to: Double,
time: TimeInterval = 0.3,
delay: TimeInterval = 0,
ease: @escaping Ease.TimingFunction = Ease.Quad.easeOut,
key: String? = nil,
onStart: StartClosure? = nil,
onComplete: CompletionClosure? = nil,
onUpdate: @escaping Tween<Double>.UpdateClosure
) -> Tween<Double> {
return Tween(from: self,
to: to,
Expand Down
56 changes: 28 additions & 28 deletions Sources/extensions/Tween+UIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import UIKit
extension UIView {

func trxCenterTo(_ to: CGPoint,
time: TimeInterval = 0.3,
delay: TimeInterval = 0,
ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut,
onStart: StartClosure? = nil,
onComplete: CompletionClosure? = nil,
onUpdate: Tween<CGPoint>.UpdateClosure? = nil) {
public func trxCenter(to: CGPoint,
time: TimeInterval = 0.3,
delay: TimeInterval = 0,
ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut,
onStart: StartClosure? = nil,
onComplete: CompletionClosure? = nil,
onUpdate: Tween<CGPoint>.UpdateClosure? = nil) {
Tween(from: self.center,
to: to,
time: time,
Expand All @@ -21,13 +21,13 @@
}).start()
}

func trxCenterFrom(_ from: CGPoint,
time: TimeInterval = 0.3,
delay: TimeInterval = 0,
ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut,
onStart: StartClosure? = nil,
onComplete: CompletionClosure? = nil,
onUpdate: Tween<CGPoint>.UpdateClosure? = nil) {
public func trxCenter(from: CGPoint,
time: TimeInterval = 0.3,
delay: TimeInterval = 0,
ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut,
onStart: StartClosure? = nil,
onComplete: CompletionClosure? = nil,
onUpdate: Tween<CGPoint>.UpdateClosure? = nil) {
Tween(from: from,
to: self.center,
time: time,
Expand All @@ -40,13 +40,13 @@
}).start()
}

func trxFrameTo(_ to: CGRect,
time: TimeInterval = 0.3,
delay: TimeInterval = 0,
ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut,
onStart: StartClosure? = nil,
onComplete: CompletionClosure? = nil,
onUpdate: Tween<CGRect>.UpdateClosure? = nil) {
public func trxFrame(to: CGRect,
time: TimeInterval = 0.3,
delay: TimeInterval = 0,
ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut,
onStart: StartClosure? = nil,
onComplete: CompletionClosure? = nil,
onUpdate: Tween<CGRect>.UpdateClosure? = nil) {
Tween(from: self.frame,
to: to,
time: time,
Expand All @@ -59,13 +59,13 @@
}).start()
}

func trxFrameFrom(_ from: CGRect,
time: TimeInterval = 0.3,
delay: TimeInterval = 0,
ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut,
onStart: StartClosure? = nil,
onComplete: CompletionClosure? = nil,
onUpdate: Tween<CGRect>.UpdateClosure? = nil) {
public func trxFrame(from: CGRect,
time: TimeInterval = 0.3,
delay: TimeInterval = 0,
ease: @escaping Ease.TimingFunction = Ease.Quart.easeInOut,
onStart: StartClosure? = nil,
onComplete: CompletionClosure? = nil,
onUpdate: Tween<CGRect>.UpdateClosure? = nil) {
Tween(from: from,
to: self.frame,
time: time,
Expand Down
2 changes: 1 addition & 1 deletion Sources/extensions/Tweenable+Repeat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public extension Tweenable {
public func repeatTimes(_ times: UInt) -> TimeLine {
let timeLine = TimeLine()
for _ in 0..<times {
timeLine.add(self)
timeLine.add(tween: self)
}
return timeLine
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/morphable/FloatMorpher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import QuartzCore
public struct Morpher {
let precision: CGFloat

public func tween(_ from: CGFloat, to: CGFloat, ratio: Double) -> CGFloat {
public func tween(from: CGFloat,
to: CGFloat,
ratio: Double) -> CGFloat {
return from.distance(to: to) * CGFloat(ratio) / precision + from
}

Expand Down
34 changes: 17 additions & 17 deletions Sources/morphable/Morphable+CATransform3D.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ extension CATransform3D: Morphable {
Returns the value converted by ratio

*/
public static func morph(_ from: CATransform3D,
public static func morph(from: CATransform3D,
to: CATransform3D,
ratio: Double) -> CATransform3D {
return CATransform3D(m11: morpher.tween(from.m11, to: to.m11, ratio: ratio),
m12: morpher.tween(from.m12, to: to.m12, ratio: ratio),
m13: morpher.tween(from.m13, to: to.m13, ratio: ratio),
m14: morpher.tween(from.m14, to: to.m14, ratio: ratio),
m21: morpher.tween(from.m21, to: to.m21, ratio: ratio),
m22: morpher.tween(from.m22, to: to.m22, ratio: ratio),
m23: morpher.tween(from.m23, to: to.m23, ratio: ratio),
m24: morpher.tween(from.m24, to: to.m24, ratio: ratio),
m31: morpher.tween(from.m31, to: to.m31, ratio: ratio),
m32: morpher.tween(from.m32, to: to.m32, ratio: ratio),
m33: morpher.tween(from.m33, to: to.m33, ratio: ratio),
m34: morpher.tween(from.m34, to: to.m34, ratio: ratio),
m41: morpher.tween(from.m41, to: to.m41, ratio: ratio),
m42: morpher.tween(from.m42, to: to.m42, ratio: ratio),
m43: morpher.tween(from.m43, to: to.m43, ratio: ratio),
m44: morpher.tween(from.m44, to: to.m44, ratio: ratio))
return CATransform3D(m11: morpher.tween(from: from.m11, to: to.m11, ratio: ratio),
m12: morpher.tween(from: from.m12, to: to.m12, ratio: ratio),
m13: morpher.tween(from: from.m13, to: to.m13, ratio: ratio),
m14: morpher.tween(from: from.m14, to: to.m14, ratio: ratio),
m21: morpher.tween(from: from.m21, to: to.m21, ratio: ratio),
m22: morpher.tween(from: from.m22, to: to.m22, ratio: ratio),
m23: morpher.tween(from: from.m23, to: to.m23, ratio: ratio),
m24: morpher.tween(from: from.m24, to: to.m24, ratio: ratio),
m31: morpher.tween(from: from.m31, to: to.m31, ratio: ratio),
m32: morpher.tween(from: from.m32, to: to.m32, ratio: ratio),
m33: morpher.tween(from: from.m33, to: to.m33, ratio: ratio),
m34: morpher.tween(from: from.m34, to: to.m34, ratio: ratio),
m41: morpher.tween(from: from.m41, to: to.m41, ratio: ratio),
m42: morpher.tween(from: from.m42, to: to.m42, ratio: ratio),
m43: morpher.tween(from: from.m43, to: to.m43, ratio: ratio),
m44: morpher.tween(from: from.m44, to: to.m44, ratio: ratio))
}

/// Initial normalized value (usually 0.0 or self if Double convertible)
Expand Down
14 changes: 7 additions & 7 deletions Sources/morphable/Morphable+CGAffineTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ extension CGAffineTransform: Morphable {
Returns the value converted by ratio

*/
public static func morph(_ from: CGAffineTransform,
public static func morph(from: CGAffineTransform,
to: CGAffineTransform,
ratio: Double) -> CGAffineTransform {
return CGAffineTransform(a: morpher.tween(from.a, to: to.a, ratio: ratio),
b: morpher.tween(from.b, to: to.b, ratio: ratio),
c: morpher.tween(from.c, to: to.c, ratio: ratio),
d: morpher.tween(from.d, to: to.d, ratio: ratio),
tx: morpher.tween(from.tx, to: to.tx, ratio: ratio),
ty: morpher.tween(from.ty, to: to.ty, ratio: ratio))
return CGAffineTransform(a: morpher.tween(from: from.a, to: to.a, ratio: ratio),
b: morpher.tween(from: from.b, to: to.b, ratio: ratio),
c: morpher.tween(from: from.c, to: to.c, ratio: ratio),
d: morpher.tween(from: from.d, to: to.d, ratio: ratio),
tx: morpher.tween(from: from.tx, to: to.tx, ratio: ratio),
ty: morpher.tween(from: from.ty, to: to.ty, ratio: ratio))
}

/// Initial normalized value (usually 0.0 or self if Double convertible)
Expand Down
2 changes: 1 addition & 1 deletion Sources/morphable/Morphable+CGFloat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension CGFloat: Morphable {
Returns the value converted by ratio

*/
public static func morph(_ from: CGFloat,
public static func morph(from: CGFloat,
to: CGFloat,
ratio: Double) -> CGFloat {
return CGFloat(ratio)
Expand Down
6 changes: 3 additions & 3 deletions Sources/morphable/Morphable+CGPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ extension CGPoint: Morphable {
Returns the value converted by ratio

*/
public static func morph(_ from: CGPoint,
public static func morph(from: CGPoint,
to: CGPoint,
ratio: Double) -> CGPoint {
return CGPoint(x: morpher.tween(from.x, to: to.x, ratio: ratio),
y: morpher.tween(from.y, to: to.y, ratio: ratio))
return CGPoint(x: morpher.tween(from: from.x, to: to.x, ratio: ratio),
y: morpher.tween(from: from.y, to: to.y, ratio: ratio))
}


Expand Down
6 changes: 3 additions & 3 deletions Sources/morphable/Morphable+CGRect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ extension CGRect: Morphable {
Returns the value converted by ratio

*/
public static func morph(_ from: CGRect,
public static func morph(from: CGRect,
to: CGRect,
ratio: Double) -> CGRect {
return CGRect(origin: CGPoint.morph(from.origin, to: to.origin, ratio: ratio),
size: CGSize.morph(from.size, to: to.size, ratio: ratio))
return CGRect(origin: CGPoint.morph(from: from.origin, to: to.origin, ratio: ratio),
size: CGSize.morph(from: from.size, to: to.size, ratio: ratio))
}

/// Initial normalized value (usually 0.0 or self if Double convertible)
Expand Down
6 changes: 3 additions & 3 deletions Sources/morphable/Morphable+CGSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ extension CGSize: Morphable {
Returns the value converted by ratio

*/
public static func morph(_ from: CGSize,
public static func morph(from: CGSize,
to: CGSize,
ratio: Double) -> CGSize {
return CGSize(width: morpher.tween(from.width, to: to.width, ratio: ratio),
height: morpher.tween(from.height, to: to.height, ratio: ratio))
return CGSize(width: morpher.tween(from: from.width, to: to.width, ratio: ratio),
height: morpher.tween(from: from.height, to: to.height, ratio: ratio))
}
/// Initial normalized value (usually 0.0 or self if Double convertible)
public var initialValue: Double { return 0 }
Expand Down
2 changes: 1 addition & 1 deletion Sources/morphable/Morphable+Double.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension Double: Morphable {
Returns the value converted by ratio

*/
public static func morph(_ from: Double,
public static func morph(from: Double,
to: Double,
ratio: Double) -> Double {
return ratio
Expand Down
2 changes: 1 addition & 1 deletion Sources/morphable/Morphable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public protocol Morphable {
Returns the value converted by ratio

*/
static func morph(_ from: Self, to: Self, ratio: Double) -> Self
static func morph(from: Self, to: Self, ratio: Double) -> Self

/// Initial ratio value (usually 0.0 or self if Double convertible)
var initialValue: Double { get }
Expand Down
4 changes: 2 additions & 2 deletions Sources/scheduler/Proxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ extension Scheduler {
return subscriber.keys
}

func tick(_ timeStamp: TimeInterval) {
subscriber.tick(timeStamp)
func tick(time timeStamp: TimeInterval) {
subscriber.tick(time: timeStamp)
}

}
Expand Down
20 changes: 10 additions & 10 deletions Sources/scheduler/Scheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import QuartzCore
Dispatches time events to subscribers

*/
final public class Scheduler: Dispatcher {
final class Scheduler: Dispatcher {

/// Shared singleton
public static let shared = Scheduler()
Expand All @@ -19,21 +19,21 @@ final public class Scheduler: Dispatcher {
return link
}()

fileprivate var subscribers = Set<Proxy>()
private var subscribers = Set<Proxy>()

var timeStamp: TimeInterval {
return displayLink.timestamp
}

fileprivate func runIfNeeded() {
private func runIfNeeded() {
displayLink.isPaused = subscribers.count == 0
}

//MARK: subscription

func subscribe(_ subscriber: Subscriber) {
let subscription = Proxy(subscriber: subscriber)
solveOverwrite(subscriber)
solveOverwrite(with: subscriber)
subscribers.insert(subscription)
runIfNeeded()
}
Expand All @@ -48,26 +48,26 @@ final public class Scheduler: Dispatcher {
runIfNeeded()
}

@objc fileprivate func update(_ link: CADisplayLink) {
@objc private func update(_ link: CADisplayLink) {
subscribers.forEach { proxy in
proxy.tick(link.timestamp)
proxy.tick(time: link.timestamp)
}
}

//MARK: overwrite

fileprivate func solveOverwrite(_ subscriber: Subscriber) {
private func solveOverwrite(with subscriber: Subscriber) {
if subscriber.keys.count > 0 {
pauseAll(subscribersWithKeys(subscriber.keys))
pauseAll(subscribers: subscribers(keys: subscriber.keys))
}
}

fileprivate func subscribersWithKeys(_ keys: Set<String>) -> [Proxy] {
private func subscribers(keys: Set<String>) -> [Proxy] {

return subscribers.filter { $0.keys.intersection(keys).count > 0 }
}

fileprivate func pauseAll(_ subscribers: [Proxy]) {
private func pauseAll(subscribers: [Proxy]) {
subscribers.forEach { ($0.subscriber as? Tweenable)?.paused = true }
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/scheduler/Subscriber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import Foundation
protocol Subscriber: class {

var keys: Set<String> { get }
func tick(_ time: TimeInterval)
func tick(time: TimeInterval)
}
Loading

0 comments on commit d441a23

Please sign in to comment.