Error using += to append a Character to a String:

2019-07-04 11:03发布

When trying to use the += operator to append a Character to a String, I'm getting the following error:

String is not identical to UInt8

The error occurs on the puzzleOutput += char line in the code below:

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

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

    default:
       puzzleOutput += char
    }
}

println(puzzleOutput)

How can I append a Charater to a String?

标签: swift ios8
1条回答
倾城 Initia
2楼-- · 2019-07-04 11:54

The use of += to append a Character to a String was intentionally deleted from the language several betas ago. Use

puzzleOutput.append(char)

instead.

查看更多
登录 后发表回答