To join an array of characters into a string in Swift, you can use the init(_:)
initializer of the String
class, passing in the array of characters as a parameter. Here's an example:
main.swift123 chars4 lines
Alternatively, you can use the joined()
method of the Sequence
protocol, passing in an empty string as the separator, like this:
main.swift137 chars4 lines
Both methods produce the same output, which is a string containing the characters in the array.
gistlibby LogSnag