Skip to content

Instantly share code, notes, and snippets.

View okla's full-sized avatar

Sergey Pershenkov okla

View GitHub Profile
@okla
okla / DragGesture+Velocity.swift
Created February 17, 2021 16:36
SwiftUI DragGesture velocity
extension DragGesture.Value {
var velocity: CGPoint {
let decelerationRate = UIScrollView.DecelerationRate.normal.rawValue,
d = decelerationRate/(1000.0*(1.0 - decelerationRate))
return CGPoint(x: (location.x - predictedEndLocation.x)/d,
y: (location.y - predictedEndLocation.y)/d)
}
@okla
okla / gist:e5dd8fbb4e604dabcdc3
Last active April 12, 2017 12:55
Generic failable enum initialization with optional raw value in Swift 2.0
extension RawRepresentable {
init?(rawValue optionalRawValue: RawValue?) {
guard let rawValue = optionalRawValue, value = Self(rawValue: rawValue) else { return nil }
self = value
}
}