Skip to content

Instantly share code, notes, and snippets.

@GregLukosek
Created March 9, 2015 16:27
Show Gist options
  • Save GregLukosek/12dc4e01a4085b0ab1f9 to your computer and use it in GitHub Desktop.
Save GregLukosek/12dc4e01a4085b0ab1f9 to your computer and use it in GitHub Desktop.
Swift Int ordinal
extension Int {
var ordinal: String {
get {
var suffix: String = ""
var ones: Int = self % 10;
var tens: Int = (self/10) % 10;
if (tens == 1) {
suffix = "th";
} else if (ones == 1){
suffix = "st";
} else if (ones == 2){
suffix = "nd";
} else if (ones == 3){
suffix = "rd";
} else {
suffix = "th";
}
return suffix
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment