What does this print?
protocol Greet {
var name: String { get }
}
extension Greet {
func hi() -> String {
"Hi, \(name)"
}
}
struct Dev: Greet {
let name: String
}
print(Dev(name: "Sam").hi())
Try it in the online Swift Playground →
[spoiler title="Solution"]
Answer:
Hi, Sam
Explanation:
Dev gets hi() from the protocol extension, which interpolates name.
[/spoiler]