Created
March 9, 2015 16:27
-
-
Save GregLukosek/12dc4e01a4085b0ab1f9 to your computer and use it in GitHub Desktop.
Swift Int ordinal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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