Complete the code to declare a protocol named 'Vehicle'.
protocol [1] {
func drive()
}The protocol is named 'Vehicle' to define a common interface for types that can drive.
Complete the code to make 'Car' conform to the 'Vehicle' protocol.
struct Car: [1] { func drive() { print("Car is driving") } }
'Car' conforms to the 'Vehicle' protocol by adopting its name after the colon.
Fix the error in the class inheritance to use OOP correctly.
class [1] { func drive() { print("Driving") } } class SportsCar: Vehicle { }
The base class should be named 'Vehicle' so that 'SportsCar' can inherit from it.
Fill both blanks to create a protocol extension that provides a default implementation.
protocol Vehicle {
func drive()
}
extension Vehicle {
func [1]() {
print("[2] driving")
}
}The extension provides a default 'drive' method printing 'Vehicle driving'.
Fill all three blanks to create a dictionary comprehension filtering vehicles by speed.
let vehicles = ["car": 120, "bike": 80, "truck": 100] let fastVehicles = vehicles.filter { $0.value [1] [2] }.map { $0.key.uppercased() } let result = fastVehicles.reduce(into: [[3]: true]) { $0[$1] = true }
The code filters vehicles with speed greater than 90, converts keys to uppercase, and creates a dictionary with keys as uppercase vehicle names.