Skip to content

Instantly share code, notes, and snippets.

@smosko
Created October 17, 2021 14:21
Show Gist options
  • Save smosko/46b1b61c7fc48c0c42198b663d0f65bb to your computer and use it in GitHub Desktop.
Save smosko/46b1b61c7fc48c0c42198b663d0f65bb to your computer and use it in GitHub Desktop.
Swift implementation of the String.hashCode() from Java / Android
extension String {
func hashCode() -> Int32 {
unicodeScalars.map { Int32($0.value) }.reduce(0) { 31 &* $0 &+ $1 }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment