Junior
Is it necessary to create a structure that conforms to the protocol?
sobes.tech AI
Answer from AI
Yes, the structure can conform to the protocol.
protocol Greetable {
func greet()
}
struct Person: Greetable {
let name: String
func greet() {
print("Hello, my name is \(name).")
}
}
Structures that conform to protocols allow the use of both value semantics (copying) and the abstraction provided by protocols.