Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Swift playground example for how/why to use optional let properties in a class
class LetExample {
let name: String?
init(let _ name: String?) { = name
func sayMyName() -> String {
if let myName = {
return "My name is \(myName)"
} else {
return "I am the class with no name"
let example1 = LetExample("Yo Dawg")
let example2 = LetExample(nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment