Swift Object ModelLesson 26Free preview
Swift OOP
This lesson is part of Swift · All levels
Summary
This lesson examines the paradigm of object-oriented programming (OOP) in Swift as well as the fundamental comparison between Struct (Value Type) and Class (Reference Type). Swift strongly advocates the use of Struct as a first choice, while Class is used when requiring inheritance or shared reference identity.
Key points
- Class is Reference Type (saved in heap, several variables share the same instance)
- Struct is a Value Type (stored in stacks, independently copied when assigned or passed)
- Only the Class supports inheritance and deinitializers.
- Struct automatically obtains a memberwise initializer from the compiler
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.