Complete the code to declare a variable that conforms to both protocols.
protocol Drivable {
func drive()
}
protocol Flyable {
func fly()
}
var vehicle: [1]In Swift, protocol composition uses the & symbol to require conformance to multiple protocols.
Complete the function parameter type to accept any object conforming to both protocols.
func operate(vehicle: [1]) {
vehicle.drive()
vehicle.fly()
}The function parameter type uses protocol composition with & to require both protocols.
Fix the error in the variable declaration to use protocol composition correctly.
var gadget: [1]Protocol composition requires the & symbol, not | or commas.
Fill both blanks to create a function that accepts an object conforming to two protocols and calls their methods.
func performAction(on item: [1]) { item.[2]() }
The function parameter uses protocol composition, and the method called is drive().
Fill all three blanks to create a dictionary comprehension that maps names to objects conforming to two protocols, filtering by a condition.
let fleet = ["car": carObj, "plane": planeObj] let activeFleet = fleet.filter { $0.value is [1] } .mapValues { $0 as! [2] } .filter { $0.value.[3]() }
The filter checks if the value conforms to both protocols, then casts it, and finally calls fly() method.