0
0
Swiftprogramming~5 mins

Protocol inheritance in Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is protocol inheritance in Swift?
Protocol inheritance means one protocol can require all the properties and methods of another protocol. It lets you build new protocols based on existing ones, like stacking rules.
Click to reveal answer
beginner
How do you declare a protocol that inherits from another protocol in Swift?
You write the new protocol name followed by a colon and the name of the protocol it inherits from. Example: protocol B: A { } means B inherits from A.
Click to reveal answer
intermediate
Can a protocol inherit from multiple protocols in Swift?
Yes, a protocol can inherit from more than one protocol by listing them separated by commas. Example: protocol C: A, B { } means C inherits from both A and B.
Click to reveal answer
intermediate
What happens if a protocol inherits from another protocol with required properties or methods?
The inheriting protocol also requires those properties or methods. Any type adopting the new protocol must implement all requirements from both protocols.
Click to reveal answer
beginner
Why use protocol inheritance instead of just one big protocol?
Protocol inheritance helps keep code organized and flexible. You can build small, focused protocols and combine them as needed, making your code easier to understand and reuse.
Click to reveal answer
How do you declare a protocol B that inherits from protocol A in Swift?
Aprotocol B: A { }
Bprotocol B inherits A { }
Cprotocol B extends A { }
Dprotocol B -> A { }
Can a Swift protocol inherit from multiple protocols?
AYes, by listing protocols separated by commas
BYes, but only two protocols max
CNo, only one protocol can be inherited
DNo, protocols cannot inherit
If protocol B inherits from protocol A, what must a type conforming to B do?
AImplement only B's requirements
BNo implementation needed
CImplement only A's requirements
DImplement requirements of both A and B
Why is protocol inheritance useful?
ATo avoid writing any code
BTo create one big protocol with all features
CTo organize and combine small protocols flexibly
DTo make protocols slower
Which keyword is used to declare a protocol in Swift?
Astruct
Bprotocol
Cclass
Dinterface
Explain how protocol inheritance works in Swift and why it is useful.
Think about how one protocol can build on another and how that helps keep code clean.
You got /4 concepts.
    Describe what a type must do when it conforms to a protocol that inherits from other protocols.
    Remember that inherited protocols add to the list of rules a type must follow.
    You got /3 concepts.