Skip to content

Instantly share code, notes, and snippets.

@maml
Created March 5, 2016 00:42
Show Gist options
  • Save maml/fe1803494e7c8d48d7bf to your computer and use it in GitHub Desktop.
Save maml/fe1803494e7c8d48d7bf to your computer and use it in GitHub Desktop.
For a given Int you can get the appropriate suffx
extension Int {
public func suffix() -> String {
let absSelf = abs(self)
switch (absSelf % 100) {
case 11...13:
return "th"
default:
switch (absSelf % 10) {
case 1:
return "st"
case 2:
return "nd"
case 3:
return "rd"
default:
return "th"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment