Complete the code to declare a protocol named 'Drivable'.
protocol [1] {
func drive()
}The protocol name should be 'Drivable' to match the intended design.
Complete the code to make 'Car' conform to the 'Drivable' protocol.
struct Car: [1] { func drive() { print("Car is driving") } }
The struct 'Car' must conform to the 'Drivable' protocol to implement the 'drive' method.
Fix the error in the protocol extension to provide a default implementation.
extension Drivable {
func [1]() {
print("Default driving behavior")
}
}The method name in the extension must match the protocol's method name exactly, which is 'drive'.
Fill both blanks to create a protocol and a struct that uses protocol-oriented programming.
protocol [1] { func [2]() } struct Bike: [1] { func [2]() { print("Bike is moving") } }
The protocol is named 'Movable' with a method 'move()'. The struct 'Bike' conforms to 'Movable' and implements 'move()'.
Fill all three blanks to create a protocol with a default implementation and a struct that uses it.
protocol [1] { func [2]() } extension [1] { func [2]() { print("Default implementation") } } struct Scooter: [1] {}
The protocol is 'Rideable' with method 'ride()'. The extension provides a default 'ride()' implementation. The struct 'Scooter' conforms to 'Rideable' and uses the default method.