Complete the code to declare a protocol named Printable.
protocol [1] {
func printDescription()
}The protocol is named Printable to match the requirement.
Complete the code to add a default implementation for printDescription() in a protocol extension.
extension Printable {
func [1]() {
print("Default description")
}
}The method name must match the protocol requirement: printDescription().
Fix the error in the struct that conforms to Printable but does not implement printDescription().
struct Document: Printable {
var title: String
func [1]() {
print("Document title: \(title)")
}
}The struct must implement printDescription() or use the default implementation.
Fill both blanks to create a protocol extension that adds a new method and a default implementation.
extension Printable {
func [1]() {
print("Extra info")
}
func [2]() {
print("Default description")
}
}The new method is named extraInfo() and the default implementation for the protocol method is printDescription().
Fill all three blanks to create a struct that uses the default implementation and calls the extra method.
struct Report: Printable {
var name: String
func [1]() {
print("Report name: \(name)")
}
func show() {
[2]()
[3]()
}
}The struct overrides printDescription() and calls it and extraInfo() inside show().