Complete the code to declare a protocol named 'Drivable'.
protocol [1] {
func drive()
}The protocol name should be 'Drivable' to match the 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 'drive()'.
Fix the error in the code by completing the protocol method requirement.
protocol Drivable {
func [1]()
}
struct Bike: Drivable {
func drive() {
print("Bike is driving")
}
}The protocol requires a method named 'drive()' which must be implemented by conforming types.
Fill both blanks to create a protocol extension that provides a default implementation.
protocol [1] { func start() } extension [2] { func start() { print("Starting...") } }
The protocol and its extension must have the same name 'Startable' to provide default behavior.
Fill all three blanks to create a protocol with a property and a method, then extend it with default behavior.
protocol [1] { var name: String { get } func [2]() } extension [3] { func greet() { print("Hello, \(name)!") } }
The protocol 'Greetable' requires a 'name' property and a 'greet()' method. The extension provides a default 'greet()' implementation.