Skip to content

Instantly share code, notes, and snippets.

@siong1987
Created October 26, 2015 21:55
Show Gist options
  • Save siong1987/818594918d63e84cc2cd to your computer and use it in GitHub Desktop.
Save siong1987/818594918d63e84cc2cd to your computer and use it in GitHub Desktop.
func personName(firstName: String, lastName: String?) -> String {
guard let lastName = lastName else {
return "\(firstName)"
}
return "\(firstName) \(lastName)"
}
personName("Siong", lastName: "Ong") // prints "Siong Ong"
personName("Siong", lastName: nil) // prints "Siong"
personName("Siong") // This dosen't work but it should, nil should be auto-assigned to optional parameter :(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment