How to customise initialization with input parameters in Swift?

We can provide initialization parameters as a part of initializer definition. The syntax for initializer is same as function and method parameters. We can use both argument labels and parameter name along with its type to customize the initializer. Argument labels are used when calling the initializer. Parameter names are used within the initializer. We can provide multiple initializers with unique parameter names for a single type. During initialization process , a particular initializer is selected based on the argument label.Since initializers don’t have a identifying name before the parentheses, the name and type of parameter values play important role in identifying which initializer must be used. If no argument label is provided, Swift uses default argument label(same as parameter name) for each custom initializer we provide for a type.

Leave a Reply