Programming Languages
Swift
Interview
Oct 01, 2025
What is the difference between struct and class in Swift?
Detailed Explanation
Key differences: 1) Value vs Reference types - structs are value types (copied), classes are reference types (shared), 2) Inheritance - classes support inheritance, structs do not, 3) Identity operators - classes use === and !==, structs cannot, 4) Deinitializers - only classes have deinit, 5) Reference counting - only classes use ARC, 6) Mutability - struct methods need mutating keyword to modify properties. Use structs for simple data, classes for complex objects with inheritance.
Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts