Skip to content

Instantly share code, notes, and snippets.

@tarunon
Created March 24, 2017 05:27
Show Gist options
  • Save tarunon/6e63b708140392564418eb80ac64e899 to your computer and use it in GitHub Desktop.
Save tarunon/6e63b708140392564418eb80ac64e899 to your computer and use it in GitHub Desktop.
lazy var fatalError is a solution that instead of ImplicitlyUnwrappedOptional
func undefined<T>(_ funcName: String=#function) -> T {
fatalError("\(funcName) is undefined.")
}
class A {
lazy var parameter: Int = undefined()
}
let a = A()
a.parameter = 100
a.parameter
let b = A()
b.parameter // fatalError
let c = A()
c.parameter = 100
// c.parameter = nil // cannot insert nil. If you use Int!, you can set nil value again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment