You can create a Swift extension on the String
type to convert a string from camel case to snake case. Here's an example implementation:
main.swift798 chars30 lines
You can use this extension on any String
object to convert it from camel case to snake case, like this:
main.swift170 chars4 lines
This extension iterates through each character in the input string and checks if it is an uppercase character. If it is, it appends an underscore followed by the lowercase version of the character to the snake case string. If the character is not uppercase, it simply appends it to the snake case string.
gistlibby LogSnag