I am having a hard time understanding the optionals and forced unwrapping in Swift language. I have read the book and chapters several times but I cannot understand it.
Is there a difference between the following two:
totalAmountTextField?.text.toInt()
totalAmountTextField!.text.toInt()
Also, when declaring the IBOutlets why do I always make it an optional field like this:
@IBOutlet var nameTextField :UITextField?
If I don't use the "?" at the end then it gives errors.
nameTextFieldcannot benilafter the nib has loaded, you should think about saying@IBOutlet var nameTextField: UITextField!instead. This way you don't have to unwrap it and if the outlet gets unset in the nib, you'll get a crash rather than silent failure like you would in ObjC. - Gregory Higley