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.
Swift Property Observer

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.
swift get
Swift get set

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.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
KD Knowledge Diet

KD Knowledge Diet


Software Engineer, Mobile Developer living in Seoul. I hate people using difficult words. Why not using simple words? Keep It Simple Stupid!