



In Alten iOS codebases, choosing between struct and class affects correctness, maintainability, and performance. Interviewers want to know whether you understand Swift value semantics rather than just memorizing rules.
Explain when you would use a struct versus a class in Swift for an iOS app. In your answer, cover:
A strong answer should compare the two directly, mention practical tradeoffs such as shared mutable state and ARC, and give concrete examples like models, view state, delegates, and coordinators. You do not need to discuss every Swift language feature, but you should show clear judgment about when each type is appropriate.
A struct is a value type. Assigning or passing it creates an independent copy, which reduces accidental shared state and makes code easier to reason about.
struct User {
var name: String
}
var a = User(name: "Ana")
var b = a
b.name = "Sam"
// a.name is still "Ana"
A class is a reference type. Assigning or passing it copies the reference, so multiple variables can point to the same instance and observe shared mutations.
class Session {
var token: String
init(token: String) { self.token = token }
}
let s1 = Session(token: "abc")
let s2 = s1
s2.token = "xyz"
// s1.token is now "xyz"
Classes have identity: two references may point to the exact same object instance. Structs do not have identity in the same sense; they are compared by their data, not by object instance.
class Coordinator {}
let c1 = Coordinator()
let c2 = c1
let same = (c1 === c2) // true
Structs help contain mutation because changes stay local unless the updated value is explicitly reassigned. Classes are better when shared mutable state is intentional, such as a long-lived controller or service object.
Classes participate in ARC and support inheritance, which can be useful for lifecycle-managed objects and polymorphic hierarchies. Structs do not support inheritance and usually have lower conceptual overhead.