Struct vs. Class in Swift
Structs are value types - A value type is a type whose value is copied when it’s assigned to a variable or constant, or when it’s passed to a function.
Classes are Reference-based. Unlike value types, reference types are not copied when they’re assigned to a variable or constant, or when they’re passed to a function. Rather than a copy, a reference to the same existing instance is used.
Structures and classes in Swift have many things in common. The major difference between structs and classes is that they live in different places in memory. Structs live on the Stack(that's why structs are fast) and Classes live on Heap in RAM.
Comparing Structures and Classes
Definition Syntax
Structures and classes have a similar definition syntax. You introduce structures with the struct keyword and classes with the class keyword. Both place their entire definition within a pair of braces:
Similarities
Structures and classes in Swift have many things in common. Both can:
Differences
Classes have additional capabilities that structures don’t:
Structs have additional capabilities that classes don’t:
Recommended by LinkedIn
Mutating Struct
Be Careful❗️ If you declare a constant(let) of a struct type, you can’t call the mutating method ever. So to call any mutating method declare struct type as “var”.
Struct vs. Class - Which One is Better?
It's kind of saying like which is better, a horse or a mule. They both have their pros and cons. Now similar to a mule, a struct is infertile - you can't inherit from structs or try to subclass in a struct.
The official Apple advice is that you should use a struct by default whenever you want to create a new custom object, and only turn it into a class when you find that you need inheritance or you need to be able to work with Objective-C code. And then, in that case, turn the struct into a class. So in certain cases, you still need to rely on classes, but start with a struct and only go up if needed. This is the same advice for Swift access levels. Start with the least inclusive, most “private” access level, and only increase its access level as and when needed.
Conclusion
To dig into details, Lookup Swift Docs about Structures and Classes
How the memory management works for Struct, As ARC works for reference types.