Complete the code to declare a protocol named 'Greetable'.
protocol [1] {
func greet() -> String
}The protocol name should be 'Greetable' as declared.
Complete the protocol extension to provide a default implementation for 'greet()'.
extension Greetable {
func greet() -> String {
return [1]
}
}The default implementation returns the string "Hello!".
Fix the error by completing the struct declaration that conforms to 'Greetable'.
struct Person: [1] {
var name: String
}The struct must conform to the 'Greetable' protocol to use its default implementation.
Fill both blanks to override the default 'greet()' method in the struct.
extension Person {
func greet() -> String {
return [1] + ", " + [2]
}
}The method returns "Hi, " plus the person's name.
Fill all three blanks to create a dictionary that maps names to greetings for a list of people.
let greetings = Dictionary(uniqueKeysWithValues: people.filter({ person in person.name.count [2] 3 && person.greet() [3] "Hello!" }).map({ person in (person.name, person.[1]()) }))This creates a dictionary where keys are names and values are greetings, filtering names longer than 3 characters and greetings not equal to "Hello!".