Why inheritance is class-only in Swift
📖 Scenario: Imagine you are building a simple app to manage different types of vehicles. You want to share common features like speed and capacity but also have specific features for cars and bicycles.
🎯 Goal: Learn why inheritance in Swift works only with classes and not with structs or enums by creating a simple class hierarchy.
📋 What You'll Learn
Create a base class called
Vehicle with properties speed and capacityCreate a subclass called
Car that inherits from Vehicle and adds a property brandCreate a subclass called
Bicycle that inherits from Vehicle and adds a property hasBasketPrint details of a
Car and a Bicycle instance💡 Why This Matters
🌍 Real World
Inheritance helps organize code when building apps with related objects like vehicles, animals, or UI elements.
💼 Career
Understanding class-only inheritance is important for Swift developers to design clean, reusable, and maintainable code.
Progress0 / 4 steps