In Swift 3, the String
structure does not seem to have an initializer init(_: Int)
that will allow the conversion from an Int
to a String
. My question is why does let i = String(3)
work? What String
method or initializer is it calling? Thanks.
It's calling init(_:)
(or init(_:)
for UnsignedInteger
) arguments of the String
class.
Rather than defining separate initializers for Int
, Int64
, Int32
, Int16
, Int8
, UInt
, UInt64
, UInt32
, UInt16
, and UInt8
, Apple made two generic initializers: one for SignedInteger
types, and one for UnsignedInteger
types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With