Cannot convert value of type 'Character' to type 'String' in coercion

Viewed 8392

In Swift, I would expect the following to be a perfectly valid code:

let snailCharacter: Character = ""
let snailString = snailCharacter as String

But apparently, it produces an error:

Cannot convert value of type 'Character' to type 'String' in coercion

Solution to this is to use String initializer like this:

let snailString = String(snailCharacter)

I thought Character is kind of a subset of String, so that surprised me. Why is it forbidden to cast Character to String?

I'm using Swift 4 in Xcode 9 beta 4.

2 Answers
Related