What is the Swift type system — structs, classes, enums?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Swift & iOS development. It reveals whether you understand the building blocks that more complex concepts rely on.
Answer
Swift has three primary named types: Struct: value type, no inheritance, can conform to protocols. Preferred for most types in Swift: struct User { let id: UUID let name: String var email: String mutating func updateEmail(_ new: String) { email = new } // mutating needed for value types }. Class: reference type, supports inheritance, reference counting (ARC): class Animal { var name: String init(name: String) { self.name = name } func speak() { print("\(name) says something") } } class Dog: Animal { override func speak() { print("\(name) says Woof!") } }. Enum: value type, can have associated values, raw values, methods: enum NetworkError: Error { case timeout case notFound(url: String) case serverError(code: Int) case noConnection } // Usage: throw NetworkError.notFound(url: "https://api.example.com") // Pattern matching: switch error { case .timeout: print("Timed out") case .notFound(let url): print("Not found: \(url)") case .serverError(let code): print("Server error: \(code)") default: break } // Raw values: enum Direction: String { case north = "N", south = "S", east = "E", west = "W" } Direction.north.rawValue // "N" Direction(rawValue: "S") // .south. Choosing: Struct for data models (no inheritance, thread-safe); Class for objects with identity and shared state; Enum for finite set of related values.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last Swift & iOS project, I used this when...' immediately makes your answer more credible and memorable.