Skip to content

Commit 7d5df66

Browse files
manucheriSundin
authored andcommitted
Add Swift version to podspec file + format & lint the code
Cocoapods 1.4.0 includes the ability to specify the Swift version in the podspec (previously this could be done by creating a separate file in the repo). This allows Cocoapods to know which target to set for the Pod - instead of going for a default value, which can cause troubles when mixing Swift 4 and 3 code. This change adds the Swift version to the Podspec. The other changes includes some basic formatting and linting (mostly removal of whitespace and following Swift styleguides). Also updates the Podspec version.
1 parent c039915 commit 7d5df66

File tree

9 files changed

+106
-104
lines changed

9 files changed

+106
-104
lines changed

KSSwipeStack.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'KSSwipeStack'
11-
s.version = '0.4.2'
11+
s.version = '0.4.3'
1212
s.summary = 'A Swift card swiping library created by Kicksort Consulting AB'
1313

1414
# This description is used to generate tags and improve search results.
@@ -34,6 +34,7 @@ DOCS: https://github.com/Kicksort/KSSwipeStack
3434
s.source = { :git => 'https://github.com/kicksort/KSSwipeStack.git', :tag => s.version.to_s }
3535

3636
s.ios.deployment_target = '8.0'
37+
s.swift_version = '4.0'
3738

3839
s.source_files = 'KSSwipeStack/Classes/**/*'
3940

KSSwipeStack/Classes/PanDirectionGestureRecognizer.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ public enum PanDirection {
1818

1919
public class PanDirectionGestureRecognizer: UIPanGestureRecognizer {
2020
let direction: PanDirection
21-
21+
2222
init(direction: PanDirection, target: AnyObject, action: Selector) {
2323
self.direction = direction
2424
super.init(target: target, action: action)
2525
}
26-
27-
override public func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
26+
27+
public override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
2828
super.touchesMoved(touches, with: event)
29-
29+
3030
if state == .began {
3131
guard let view = self.view else {
3232
return
3333
}
34-
34+
3535
let v = velocity(in: view)
3636
switch direction {
3737
case .Horizontal where fabs(v.y) > fabs(v.x):

KSSwipeStack/Classes/SwipableData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
/**
12-
Protocol which must be implemented by all data models meant to be swiped in the card stack.
12+
Protocol which must be implemented by all data models meant to be swiped in the card stack.
1313
*/
1414
public protocol SwipableData {
1515
/**

KSSwipeStack/Classes/SwipableView.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,59 @@ import UIKit
1212
*/
1313
open class SwipableView: UIView {
1414
private var data: SwipableData?
15-
15+
1616
public override init(frame: CGRect) {
1717
super.init(frame: frame)
1818
}
19-
20-
required public init?(coder aDecoder: NSCoder) {
19+
20+
public required init?(coder aDecoder: NSCoder) {
2121
super.init(coder: aDecoder)
2222
}
23+
2324
/**
24-
Is fired when the view is being moved within the stack.
25+
Is fired when the view is being moved within the stack.
2526
## You can here change the visuals of the view based on:
2627
- Whether or not the card is being swiped to the right (liked) or (disliked)
2728
- The requested opacity of any overlays the view might have, based on the x-position of the view.
28-
29+
2930
- parameter like: true for like (right) and false for dislike (left)
3031
- parameter opacity: the requested opacity of overlays. Based on x-position
3132
*/
3233
open func respondToSwipe(like: Bool, opacity: Float) {
3334
}
34-
35+
3536
/**
36-
Should contain logic to reset the view to its initial, visual state.
37+
Should contain logic to reset the view to its initial, visual state.
3738
This is for example called when a card is released, and snaps back to the center of the view.
3839
*/
3940
open func resetView() {
4041
}
41-
42+
4243
/**
4344
This is being fired when a view is 'dimissed' from the stack.
4445
For example when it has been swiped away and left the view.
4546
*/
4647
open func respondToDismiss() {
4748
}
49+
4850
/**
4951
Set the data this SwipableView is a representation of.
5052
- parameter data: The data it is meant to represent.
51-
53+
5254
*/
5355
open func setData(_ data: SwipableData) {
5456
self.data = data
5557
}
56-
58+
5759
/**
5860
Get the data this SwipableView is a representation of.
5961
- returns: The data it is meant to represent.
60-
62+
6163
*/
6264
open func getData() -> SwipableData? {
6365
return data
6466
}
65-
67+
6668
/**
6769
Should return whether or not the user is to be allowed to undo swiping this card.
6870
*/

KSSwipeStack/Classes/SwipeDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ public protocol SwipeDelegate {
1515
- parameter swipe: The swipe which just occured.
1616
*/
1717
func onNext(_ swipe: Swipe)
18-
}
18+
}

KSSwipeStack/Classes/SwipeDirection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public enum SwipeDirection {
1313
case right
1414
case up
1515
case down
16-
16+
1717
func getSwipeEndpoint() -> CGPoint {
1818
switch self {
1919
case .left:

KSSwipeStack/Classes/SwipeHelper.swift

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ class SwipeHelper {
1313
private let swipeViewSize: CGSize
1414
private let swipeViewCenter: CGPoint
1515
open var options = SwipeOptions()
16-
16+
1717
init(with frame: CGRect) {
1818
swipeViewSize = frame.size
1919
swipeViewCenter = CGPoint(x: frame.width / 2, y: frame.height / 2)
2020
}
21-
21+
2222
/// Move and animate a view to a desired position
2323
///
2424
/// - Parameters:
@@ -28,7 +28,7 @@ class SwipeHelper {
2828
func move(_ card: UIView, duration: Double = 0.25, toPoint: CGPoint) {
2929
move(card, duration: duration, toPoint: toPoint, completion: {})
3030
}
31-
31+
3232
/// Move and animate a view to a desired position
3333
///
3434
/// - Parameters:
@@ -44,20 +44,21 @@ class SwipeHelper {
4444
completion()
4545
})
4646
}
47+
4748
/// Move and animate a view to a desired position,
4849
/// transforming the view according to the current SwipeOptions
4950
/// Uses dismissAnimationDuration set in SwipeOptions
5051
/// - Parameters:
5152
/// - card: The view to be move
5253
/// - toPoint: Destination of the move action
5354
/// - completion: Callback fireing when the animation is done and the view is moved.
54-
55+
5556
func moveFastAndTransform(_ card: SwipableView, toPoint: CGPoint, completion: @escaping () -> Void) {
5657
addBorderToCard(card)
57-
58-
let rotation = self.calculateRotationAnimation(cardCenter: toPoint)
59-
let scale = self.calculateScaleAnimation(cardCenter: toPoint)
60-
58+
59+
let rotation = calculateRotationAnimation(cardCenter: toPoint)
60+
let scale = calculateScaleAnimation(cardCenter: toPoint)
61+
6162
card.respondToSwipe(like: toPoint.x > 0, opacity: toPoint.equalTo(swipeViewCenter) ? 0.0 : 1.0)
6263
UIView.animate(withDuration: options.dismissAnimationDuration, delay: 0, options: UIViewAnimationOptions.curveLinear, animations: {
6364
card.center = toPoint
@@ -67,43 +68,43 @@ class SwipeHelper {
6768
completion()
6869
})
6970
}
70-
71+
7172
/// Calculate the magnitude if a throw based on the velocity vector
7273
/// Used when determining if a card has been thrown 'hard enough' to be dismissed.
7374
/// - Parameter velocity: velocity vector of the gesture
7475
/// - Returns: magnitude of the throw
75-
func calculateThrowMagnitude(for velocity: CGPoint ) -> Float {
76+
func calculateThrowMagnitude(for velocity: CGPoint) -> Float {
7677
let velXSq = Float(velocity.x) * Float(velocity.x)
7778
let velYSq = Float(velocity.y) * Float(velocity.y)
7879
return sqrtf(velXSq + velYSq)
7980
}
80-
81+
8182
/// Returns a view to its original visual state in regards to border, rotation and scale.
8283
/// Animates the reset of the view
8384
/// - Parameter card: View to reset
8485
func resetCard(_ card: UIView) {
8586
let rotation = CATransform3DMakeRotation(0, 0, 0, 1)
8687
let scale = CATransform3DMakeScale(1.0, 1.0, 1.0)
87-
88+
8889
let borderAnim = CABasicAnimation(keyPath: "borderWidth")
8990
borderAnim.fromValue = card.layer.borderWidth
9091
borderAnim.toValue = 0
9192
borderAnim.duration = 0.1
9293
card.layer.borderWidth = 0
93-
94+
9495
let cornerAnim = CABasicAnimation(keyPath: "cornerRadius")
9596
cornerAnim.fromValue = card.layer.cornerRadius
9697
cornerAnim.toValue = 0
9798
cornerAnim.duration = 0.1
9899
card.layer.cornerRadius = 0
99-
100+
100101
let both = CAAnimationGroup()
101102
both.duration = 0.1
102103
both.animations = [cornerAnim, borderAnim]
103104
both.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
104-
105+
105106
card.layer.add(both, forKey: "both")
106-
107+
107108
UIView.animate(withDuration: 0.1) {
108109
card.layer.transform = CATransform3DConcat(rotation, scale)
109110
}
@@ -118,18 +119,18 @@ class SwipeHelper {
118119
card.layer.transform = CATransform3DConcat(rotation, scale)
119120
addBorderToCard(card)
120121
}
121-
122+
122123
func addBorderToCard(_ card: UIView) {
123124
card.layer.borderWidth = 10
124125
card.layer.borderColor = UIColor.white.cgColor
125126
card.layer.cornerRadius = 10
126127
card.layer.masksToBounds = true
127128
}
128-
129+
129130
private func calculateScaleAnimation(cardCenter: CGPoint) -> CATransform3D {
130131
let horizontalDistance = calculateHorizontalDistanceFromCenter(cardCenter)
131132
let verticalDistance = calculateVerticalDistanceFromCenter(cardCenter)
132-
133+
133134
var scaleFactor = CGFloat(0)
134135
if horizontalDistance >= verticalDistance {
135136
scaleFactor = CGFloat(1 - horizontalDistance / 800.0)
@@ -138,45 +139,45 @@ class SwipeHelper {
138139
}
139140
return CATransform3DMakeScale(scaleFactor, scaleFactor, 1.0)
140141
}
141-
142+
142143
private func calculateRotationAnimation(cardCenter: CGPoint) -> CATransform3D {
143144
let xFromCenter = Double(cardCenter.x - swipeViewSize.width / 2)
144-
var rads = CGFloat(xFromCenter/10.0 * .pi / 180.0)
145+
var rads = CGFloat(xFromCenter / 10.0 * .pi / 180.0)
145146
if abs(rads) > 1.4 {
146147
rads = -rads
147148
}
148149
return CATransform3DMakeRotation(rads, 0, 0, 1)
149150
}
150-
151+
151152
/// Calculates the distance in the horizontal plane from the position of a view to the center of the screen
152153
///
153154
/// - Parameter cardCenter: A positonal coordinate, preferably the center of a view.
154155
/// - Returns: The horizontal distance from the center of the screen
155156
private func calculateHorizontalDistanceFromCenter(_ cardCenter: CGPoint) -> Double {
156157
return Double(abs(cardCenter.x - swipeViewSize.width / 2))
157158
}
158-
159+
159160
/// Calculates the distance in the vertical plane from the position of a view to the center of the screen
160161
///
161162
/// - Parameter cardCenter: A positonal coordinate, preferably the center of a view.
162163
/// - Returns: The vertical distance from the center of the screen
163164
private func calculateVerticalDistanceFromCenter(_ cardCenter: CGPoint) -> Double {
164165
return Double(abs(cardCenter.y - swipeViewSize.height / 2))
165166
}
166-
167+
167168
/// Calculate a proper destination for a dismissal of a view based on its position
168169
/// Places the view far to the left if the view is to the left the the center of the screen and vice versa.
169170
/// - Parameter card: View which endpoint to calculate
170171
/// - Returns: Proper destination for the view
171172
func calculateEndpoint(_ card: UIView) -> CGPoint {
172173
let deltaX = card.center.x - swipeViewSize.width / 2
173174
let deltaY = card.center.y - swipeViewSize.height / 2
174-
175+
175176
let k = deltaY / deltaX
176177
let toX = deltaX < 0 ? -swipeViewSize.height / 2 : swipeViewSize.width + swipeViewSize.height / 2
177178
return CGPoint(x: toX, y: toX * k)
178179
}
179-
180+
180181
/// Calculate a proper destination for a dismissal of a view based on current velocity
181182
/// Places the view far to the left if the view is currently moving to the left and vice versa.
182183
/// The angle from the center to the proposed destination of the view is based on the angle of the velocity vector
@@ -187,7 +188,7 @@ class SwipeHelper {
187188
let toX = velocity.x < 0 ? -swipeViewSize.height / 2 : swipeViewSize.width + swipeViewSize.height / 2
188189
return CGPoint(x: toX, y: toX * k)
189190
}
190-
191+
191192
/// Converts a position with coordinates with the origin of the screen as origo to one using the center of the screen as origo.
192193
/// Can be used to convert a origin value to a center value refering to the same positioning of a full screen view.
193194
/// - Parameter center: Position using origin as origo

KSSwipeStack/Classes/SwipeOptions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public struct SwipeOptions {
2121
public var refillThreshold = 10
2222
public var dismissAnimationDuration = 0.25
2323
public var freezeWhenDismissing = false
24-
25-
public init(){}
24+
25+
public init() {}
2626
}

0 commit comments

Comments
 (0)