0
0
iOS Swiftmobile~5 mins

Structs vs classes in iOS Swift - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is a struct in Swift?
A struct is a value type that stores data and copies itself when assigned or passed around. It is often used for simple data containers.
Click to reveal answer
beginner
What is a class in Swift?
A class is a reference type that stores data and shares the same instance when assigned or passed around. It supports inheritance and reference counting.
Click to reveal answer
intermediate
How do structs and classes differ in memory behavior?
Structs copy their data when assigned or passed, so each variable has its own copy. Classes share the same instance, so changes affect all references.
Click to reveal answer
intermediate
Can structs inherit from other structs or classes?
No, structs cannot inherit from other structs or classes. Only classes support inheritance in Swift.
Click to reveal answer
beginner
When should you choose a struct over a class in Swift?
Choose a struct when you want simple, safe data containers that copy on assignment and don’t need inheritance or shared state.
Click to reveal answer
Which of the following is true about Swift structs?
AThey are reference types.
BThey support inheritance.
CThey are value types and copy on assignment.
DThey cannot have methods.
What happens when you assign a class instance to a new variable?
AA new copy of the instance is created.
BThe new variable points to the same instance.
CThe instance is deleted.
DThe instance becomes immutable.
Which feature is only available in classes but not structs?
AInheritance
BStored properties
CMethods
DInitializers
Why might you prefer structs for simple data models?
ABecause they are reference types.
BBecause they automatically share data.
CBecause they support inheritance.
DBecause they copy data, avoiding unexpected changes.
Which of these is NOT a characteristic of Swift classes?
ACopies data on assignment
BSupports inheritance
CReference type
DCan have deinitializers
Explain the main differences between structs and classes in Swift.
Think about how data is stored and shared.
You got /4 concepts.
    When would you choose a struct instead of a class for your data model in an iOS app?
    Consider safety and simplicity.
    You got /4 concepts.