Skip to content

Instantly share code, notes, and snippets.

@efremidze
Last active August 9, 2017 07:32
Show Gist options
  • Save efremidze/5515433fb474917d2e5f122d41852e84 to your computer and use it in GitHub Desktop.
Save efremidze/5515433fb474917d2e5f122d41852e84 to your computer and use it in GitHub Desktop.
extension Dictionary where Value == Any {
func value<T>(forKey key: Key, defaultValue: @autoclosure () -> T) -> T {
guard let value = self[key] as? T else { return defaultValue() }
return value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment