Created
March 24, 2017 05:27
-
-
Save tarunon/6e63b708140392564418eb80ac64e899 to your computer and use it in GitHub Desktop.
lazy var fatalError is a solution that instead of ImplicitlyUnwrappedOptional
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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