Skip to content

Instantly share code, notes, and snippets.

@christopherweems
christopherweems / int-range-in-switch.swift
Created March 18, 2020 15:15
Swift: Incomplete Int range in `switch`
// Swift should suggest the remaining cases,
// to a novice it is not clear why this does not cover
// the full range of values of an Int
switch semVersion.major {
case 10...:
return 6
case ...9:
return 5
@christopherweems
christopherweems / UIViewAnimationCurve+ToOptions.swift
Created December 8, 2015 15:08
Convert from UIViewAnimationCurve to UIViewAnimationCurveOptions
// Simple function converting from UIViewAnimationCurve to UIViewAnimationCurveOptions
// Not all UIViewAnimationCurve values have a specified equivalent UIViewAnimationCurveOptions,
// making it tricky to use the animation curve of the keyboard with UIView.animateWithDuration(...) API.
// This works as late as iOS 9.1, but could change in the future.
extension UIViewAnimationCurve {
func toOptions() -> UIViewAnimationOptions {
return UIViewAnimationOptions(rawValue: UInt(rawValue << 16))
}
}