SLN SLN - 1 year ago 81
Swift Question

What do you mean by initializer? Is it a process or it is a noun?

I'm reading the officital Swift documents "The Swift Programming language (Swift 2.2)". In the topics of Optionals under the Baseics section
I found the following descriptions which has somthing to do with initializer.

"The example below uses the initializer to try to convert a String into an Int:

let possibleNumber = "123"
let convertedNumber = Int(possibleNumber)

Because the initializer might fail, it returns an optional Int, rather than an Int."

I wonder what exaclty the initializer means. Is it the object convertedNumver is acturally the initializer or the string "123" or the whole process is called the initializer. Can someone please explain it for me?

Thanks A lot


Answer Source

convertedNumber is an Object. Int(...) actually initialize the convertedNumber Object for you. As conversion String to Int is not guaranteed to success, convertedNumber is optional.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download