Difference between a struct and a class in Swift.

Every swift developer who has at least 6 months experience will know about Struct, Enum, and Class. Everyone use them on a regular basis without knowing what they are and when and where to use them. I will try to make it simple.

image source: stocksnap

Value Types and Reference Types

An instance of a class is traditionally known as an object. But it is better to use the term Instance as we are dealing with struct and enum as well.

Class

Struct

What are the common factors between struct and class?

Classes have additional capabilities that structures don’t have:

Syntax

Memberwise Initializers for Structure Types

struct Resolution {var width = 0var height = 0}let vga = Resolution(width: 640, height: 480)

When and where to use them?

Must read: Choosing Between Structures and Classes — Apple doc

If you enjoyed reading this post, please share and give some claps so others can find it 👏👏👏👏👏 !!!!

iOS and tvOS developer, dreamer, photographer 🤨