Skip to content

Instantly share code, notes, and snippets.

@mrcljx
Created June 3, 2014 15:28
Show Gist options
  • Save mrcljx/ee776083c1b0542dbe9f to your computer and use it in GitHub Desktop.
Save mrcljx/ee776083c1b0542dbe9f to your computer and use it in GitHub Desktop.
Bang.swift
class Card {}
class Customer {
var optionalCard: Card?
var card: Card
init() {
self.card = Card() // required to avoid compiler error (card2 would be nil)
}
}
let john : Customer? = Customer()
let jane : Customer = Customer()
john!.optionalCard = Card() // We need the ! just because john is Optional
if let someJohn = john {
someJohn.card = Card()
}
jane.optionalCard = Card()
jane.card = Card()
@mrcljx
Copy link
Author

mrcljx commented Jun 3, 2014

If L10 would not have the ? the whole example wouldn't need a !.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment