Declairing empty variables SWIFT | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Declairing empty variables SWIFT

I'm able to declare an empty variable like var airport: String So why do I see everyone doing it this way? var airport = String () and yes I know to adding a "?" at the end of my declarration turns it to nil until it's initialized.

11th Sep 2019, 9:50 PM
Waylan Sands
Waylan Sands - avatar
1 Answer
+ 2
var airport = String () is the same as var airport: String, both are creating a null variable of type String. The reason people create their variables this way is because they are familiar with other languages that use this somewhat similar method without parentheses. So don't worry about creating your null variable on your way, because it's correct too !
30th Sep 2019, 3:43 AM
Wardy Spirit
Wardy Spirit - avatar