Last active
March 6, 2024 15:46
-
-
Save lucianoschillagi/9d737c3f3b8add144df6b8864620b34c to your computer and use it in GitHub Desktop.
Swift @dynamicCallable attribute example
This file contains 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 | |
@dynamicCallable | |
struct PersonIntroduceYourself { | |
func dynamicallyCall(withArguments names: [String]) -> String { | |
guard names.count == 2 else { | |
return "Invalid number of arguments. | |
Please provide both first name and last name." | |
} | |
let firstName = names[0] | |
let lastName = names[1] | |
return "Hello, my name is \(firstName) \(lastName)!" | |
} | |
} | |
let introduce = PersonIntroduceYourself() | |
introduce("Luciano", "Schillagi") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment