Swift: Class vs Struct

Similarities

  • They both define properties to store values. Much like a key-value pair in Hash Maps.
  • They both have initializers to create instances with initial values. Objects can be created with initialized values to start with.
  • They can both conform to protocols. Some protocols are specific to classes, so only classes can conform to that specific protocol, but otherwise both can conform to it.
  • They can be extended via extensions for inheritance from other classes/structs.

Class Specific Capabilities

  • Classes can inherit other classes characteristics.

The Difference

Class

When to Use What

Classes

Structs

--

--

--

Software Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Playing With s3 — Leaks

The Awesome CSS mask-image Property

Night Lights With Stripped CSS Mask Image

Question 3: Don’t Close the Ticket, Fix the Problem

Question 3: Don’t Close the Ticket, Fix the Problem

Adjusting Your Sails: Finding Fulfilment in Web Development

What is AWS Timestream?

Building a Parallel Task API with Celery

WE DON’T HAVE AN ENGINEERING PROBLEM

How to Extract Any Artist’s Data Using Spotify’s API, Python, and Spotipy

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
Lawson Hung

Lawson Hung

Software Engineer

More from Medium

Struct vs Classes

Swift Range Operators

Variable Definition, Arrays, Dictionaries and Set Structures in Swift

The UIPickerView Guide (Swift Tutorial)