We already came across class, struct and enums where we declare properties and we can initialise those values on instance creation time.

Properties are two types

Stored properties

These properties will be holding values in their memory location. In the Person class we kept name and age as stored properties.

Computed properties

Some properties doesn’t require storage they will calculate or produce a value by calculating dynamically.

If you add fullName as a property in our Person class the this can use firstName and lastName to compute the fullName. This property depends on other stored or computed properties.

👋

In swift we can add additional functionality to a class, struct, enum or protocols.

extension Int {

func incrementTwice() {

self = self + self

}

}

The above code snippets adds additional function to the inbuilt Int struct defined by swift. We can utilise this to add functionalities.

Enum is a type in swift. This is similar to class and structs but it has predefined set of instances called cases

enum Days {

case sunday

case monday

case tuesday.

case wednesday

case thursday

case friday

case saturday

}

This is an example of enums.

Enum is a value type like structs

Enum can hold functions and computed properties.

It can even have an init function.

samson sunny

Bloom where you are planted

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