SLN
SLN

Reputation: 5082

What's the connection between gettable, settable and stored property, computed property

I don't think I'm crystal clear on the connection between gettable, settable and stored property and computed property.

Can I say that the gettable is somehow related to stored property and settable is somehow related to computed property

Thanks so much for your time and help for a beginner like me

Upvotes: 1

Views: 360

Answers (1)

Alexander
Alexander

Reputation: 63272

Computed properties:

  • Are not really properties at all
  • Do not have memory that stores their value
  • Are methods that present themselves as properties
  • Have a get and optional set method that can be overridden
  • Can be gettable, settable, or both.
  • Example usage:
    • Get a temperature in Celcius from a stored property that's stored in Kelvin
    • Get the area of a rectangle that's stored in a width and height stored property

Stored properties:

  • Are just like regular variables in other languages
  • Have memory that stores their value
  • Have a willSet(_:) and didSet(_:) method that can be overriden
  • Can always be read, but can be read only.
  • Example usage:
    • Store a temperature in Kelvin
    • Store a width and a height of a rectangle

Upvotes: 5

Related Questions