Uhhh... the documentation is shit; still lost

This commit is contained in:
cdricms
2023-12-26 17:29:03 +01:00
parent 40e796c8a8
commit 11789ecdbe
2 changed files with 35 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
extension String {
func camelCaseToSnakeCase() -> String {
var result = ""
var lastCharacterWasUppercase = false
for character in self {
if character.isUppercase {
if !result.isEmpty && !lastCharacterWasUppercase {
result.append("_")
}
result.append(character.lowercased())
lastCharacterWasUppercase = true
} else {
result.append(character)
lastCharacterWasUppercase = false
}
}
return result
}
}