This code doesn't work. It causes a segmentation fault. The entire point of initializing a variable with ! instead of ? is so I can use it with it automatically unwrapping itself. Why is this the case?
var isFoo: Bool!
override func viewDidLoad() {
super.viewDidLoad()
isFoo = true
print(getNumber())
}
func getNumber() -> Int {
return isFoo ? 1 : 0
}
instead I have to write:
func getNumber() -> Int {
return isFoo! ? 1 : 0
}
What is most annoying is that the compiler will just give me a Segmentation fault: 11, which has had me debugging for over an hour to conclude that this was where the error was introduced. It doesn't recognize there is anything wrong with the code until I try to compile. Am I missing something?