2

In the Apple Documentation :

init(_: Character)
Creates a string containing the given character.

c: The character to convert to a string.

Declaration
init(_ c: Character)

I try to create a string with a character using string init but I fail.I don't understand the declaration above.I want to create a string including "k".

Here is example:

String(_ c: "k") // fails
String("k" c: Character) // fails

What is the correct way acoording to declaration above.I don't understand what _: means in the declaration.

Can someone explain what the declaration means in human language ?

  • Have a look at [What's the _ underscore representative of in Swift References?](http://stackoverflow.com/questions/24437388/whats-the-underscore-representative-of-in-swift-references). – Martin R Dec 18 '16 at 13:38

1 Answers1

1
init(_: Character)
     ^

means the parameter doesn't have an external name. So when you call that initializer you simply put the value, without a label.

Like this

let char: Character = "A"
let word = String(char)
Luca Angeletti
  • 58,465
  • 13
  • 121
  • 148