Last active
April 9, 2018 08:29
-
-
Save Oisann/ee28aa3cb0e0b2738f81930f5b3fcc7c to your computer and use it in GitHub Desktop.
Should This Name Use S After Apostrophe????
This file contains 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
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