Skip to content

Instantly share code, notes, and snippets.

@Oisann
Last active April 9, 2018 08:29
Show Gist options
  • Save Oisann/ee28aa3cb0e0b2738f81930f5b3fcc7c to your computer and use it in GitHub Desktop.
Save Oisann/ee28aa3cb0e0b2738f81930f5b3fcc7c to your computer and use it in GitHub Desktop.
Should This Name Use S After Apostrophe????
class ShouldThisNameUseSAfterApostrophe {
func check(_ name: String) -> String {
return name.lowercased().last == "s" ? "" : "s"
}
}
extension String {
func toPossesive() -> String {
let stnusaa = ShouldThisNameUseSAfterApostrophe()
return "\(self)'\(stnusaa.check(self))"
}
}
/*
USAGE:
let name = "Jonas"
let text = "This is \(name.toPossesive()) car." //This is Jonas' car.
let name = "Bjørn-Vidar"
let text = "This is \(name.toPossesive()) boat." //This is Bjørn-Vidar's boat.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment