Skip to content

Instantly share code, notes, and snippets.

@ashalva
Last active May 9, 2018 06:40
Show Gist options
  • Save ashalva/a2dc0a8d6f79526264aa3e02c2316e52 to your computer and use it in GitHub Desktop.
Save ashalva/a2dc0a8d6f79526264aa3e02c2316e52 to your computer and use it in GitHub Desktop.
To lower case implementation in swift.
func toLowerCase(string: String) -> String {
var str = string as NSString
for i in 0...(str.length - 1) {
if str.character(at: i) >= 65 && str.character(at: i) <= 90 {
let changeValue = str.character(at: i) + 32
str = str.replacingCharacters(in: NSMakeRange(i, 1), with: String(Character(UnicodeScalar(changeValue)!))) as NSString
}
}
return str as String
}
toLowerCase(string: "convErTing StrinG inTo Lower Case") //result "converting string into lower case"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment