Error when using + = to add character to string: String is not identical to UInt8

When trying to use the operator +=

to add Character

to String

, I get the following error:

String is not identical to UInt8

The error is in the line puzzleOutput += char

in the code below:

let puzzleInput = "great minds think alike "
var puzzleOutput = ""

for char in puzzleInput
    switch char
    case "a","e","i","o","u":

       puzzleOutput += char



How to add Charater

to String



source to share

1 answer

The use of + = to add a character to a String was deliberately removed from the language several beta versions ago. Use

puzzleOutput.append (char)




All Articles