Learn Swift Fundamentals by preparing for Job Interview, Questions 66~ 69 For OOP Property Observer
66) What are Property Observers?
- willSet and didSet are the property observers.
- These blocks get triggered when there is a change in the value.
67) What is get and set? How to declare get only or set property?
- The read and write access of a property can be declared by using get and set keywords.
- You can access the value of get only property but cannot set the value.
- A property must contain at least get.
68) Can a property has only setter(set)?
- No, Every property must contain a getter. We can declare get only property but not set only property.
69) Difference between Class vs Structures?
- Structures are value types.
- Classes are reference types.
- Structures don’t support inheritance.
- classes support inheritance.
- Structures don’t support de-initializers. ( deinit )
- Classes support deinitializers.
- Structures don’t follow Reference Counting.
- Classes follow Reference Counting.
- Mutating Keyword is needed to modify the property values in Structure’s instance methods.
- No need of mutating keyword to modify the class variable’s value.