QUESTION:
Why would Swift use something like optionals when I could just check if the value is nil or not ? Essentially, I am wondering what's the use of such a language feature, I am learning Swift atm and from my beginner perspective it seems redundant/useless.
P.S.: I am coming from Javascript.
CODE:
It seems absurd to me to do something like :
if let normalImage = imageFromFaceBook {
print(normalImage) // normalImage is a constant
} else {
print("There is no image")
}
when I could just do :
if (imageFromFacebook != nil) {
print(imageFromFacebook) // normalImage is a constant
} else {
print("There is no image")
}
like I normally do in Javascript :
if (imageFromFacebook != null) {
print(imageFromFacebook) // normalImage is a constant
} else {
print("There is no image")
}