Witch one to use: String () or String?
Depends … on how you do things!
But!
For my part, I’ve reduce bug crashing App when using: String ()
How?
- String? make’s it wait for a value from the user (problematic).
- String () set’s a nil value.
Why!
- If using String? and the user skip some steps, tap or click on a place before entering a value that is needed the App will crash.
- String () already put the nil value to the App that needs to run. The value null will appear in a text field.
Data Type
- You can use the same thing with: String (), Float (), Double (), etc.
How to code
- var stringName = String ()
- var stringName : String?
Alternative to code (it’s an other way that I found recently)
- var valueString: String! = « »
Don’t forget
The equal (=) sign and the column (:) sign is different before using it.