Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumSwiftprotocol-oriented programmingSingle-choice MCQ

A protocol provides a default implementation constrained to a specific element type. Which call resolves to the constrained default?

protocol Summable { associatedtype Value; var items: [Value] { get } } extension Summable { func describe() -> String { "generic" } } extension Summable where Value == Int { func describe() -> String { "ints: \(items.reduce(0,+))" } } struct Box<T>: Summable { let items: [T] } let a = Box(items: [1, 2, 3]) let b = Box(items: ["x", "y"]) print(a.describe(), b.describe())