Created
September 2, 2024 23:54
-
-
Save lucianoschillagi/a8cfcfc7bdeeb1478fb159cec47115bf to your computer and use it in GitHub Desktop.
Custom Implementations with Protocol Extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| protocol Greetable { | |
| var name: String { get } | |
| func greet() | |
| } | |
| extension Greetable { | |
| func greet() { | |
| print("Hello, \(name)") | |
| } | |
| } | |
| struct Person: Greetable { | |
| var name: String | |
| } | |
| let person = Person(name: "Juan") | |
| person.greet() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment