Skip to content

Instantly share code, notes, and snippets.

@lucianoschillagi
Last active March 6, 2024 15:46
Show Gist options
  • Save lucianoschillagi/9d737c3f3b8add144df6b8864620b34c to your computer and use it in GitHub Desktop.
Save lucianoschillagi/9d737c3f3b8add144df6b8864620b34c to your computer and use it in GitHub Desktop.
Swift @dynamicCallable attribute example
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