What is the difference between a Struct and a Class?
What is the difference between a Struct and a Class?
Written by
Rob Bentley Rob Bentley
Published on May 4, 2026

If you are an iOS developer applying for a job, the first “techy” question often asked is, “What is the difference between a Struct and a Class?”


The simple definition is that Structs are value types, and Classes are reference types. If you wanted to explain that in layman’s terms, it means that if you use a struct, each time it's used gets its own copy. A class will point to the same object in memory. Most often, developers default to using a Struct because it reduces errors.


So, when should you use a Class?


It's a good idea to use a Class when you want your data to have a shared state across several screens or across the entire application.


Here are three examples of when to use a class:



  1. When the specific identity of your object is important. You want to make sure that when you edit an object, it is the exact same object currently in memory. This would apply to a music player app that already has an audio session running. If you want to access the audio session from any screen, make sure you are editing the session that started it, not a copy. If you use the Struct, you would be using a copy of the session.

  2. When you need your object to be mutable. This would apply to a download manager. If you are downloading a video and it could take a long time, you want to make sure the download status is accessible from anywhere in the app. If you were to navigate away from the screen where you started a download and wanted to show a progress bar at the top of the app, you would want to make sure you are interacting with one download manager, not a copy of it.

  3. When your app requires UIKit / NSObject code. SwiftUI still does not have all the functionality that existed in UIKit. For example, using a custom camera to take pictures would require you to use a UIViewController with a HostingController to enable this feature in a SwiftUI application. If you are using a controller object for interacting with the camera, you have to use a Class. Structs did not exist in the early days of iOS development, and accessing older frameworks in the SDK requires using Classes.



I hope this is helpful knowledge for anyone trying to get hired as an iOS engineer. It was also helpful for me to brush up on some fundamentals.

Want to Read More?