Learn Swift Fundamentals by preparing for Job Interview, Questions 39 ~ 44 For Initializer
Swift has a lot of different initializers. I was very confused at first too. If you know exactly this concept, your interviewers will be impressed!
39) What is initializer?
Answer:
- Initializer is a method that constructs the object with proper default values.
40) What are the different types of initializers available in Swift?
Answer:
- Default
- Customized
- Convenience
- Failable
- Required
41) What is the default initializer in Swift?
Answer:
- init is the default initializer in Swift.
42) What is parameterized / Custom Initializer?
Answer:
- init method with some input parameters to construct the object with custom values.
43) What is designated initializer in Swift?
Answer:
Default init method is the designated initializer
44) What is convenience initializer in Swift?
Answer:
- Convenience Initializer is a kind of initializer which sets custom values for a few properties of an Object. Use convenience keyword to create convenience initializer.
- Designated initializer must be called before setting the custom values.