Skip to content

Instantly share code, notes, and snippets.

@fruitcoder
Last active September 17, 2021 16:23
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fruitcoder/94bf787671e805675e1f7bb6770d389d to your computer and use it in GitHub Desktop.
Save fruitcoder/94bf787671e805675e1f7bb6770d389d to your computer and use it in GitHub Desktop.
Returns the simulator drag coefficient when Slow Animations are enabled, otherwise (and non simulator builds) 1.0
import UIKit
#if targetEnvironment(simulator)
@_silgen_name("UIAnimationDragCoefficient") func UIAnimationDragCoefficient() -> Float
func simulatorDragCoefficient() -> CFTimeInterval {
let drag = UIAnimationDragCoefficient()
if drag > 1 {
return CFTimeInterval(drag)
}
return 1
}
#else
func simulatorDragCoefficient() -> CFTimeInterval { 1 }
#endif
@fruitcoder
Copy link
Author

Update 2020-11-25: Use targetEnvironment(simulator) instead of os() so that simulators running on Silicon Macs work as well.

@steipete
Copy link

Disclaimer: This works by pure accident, it can break any time. Do not use _silgen_name in production! https://twitter.com/harlanhaskins/status/1331637798311366657?s=21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment