With very few exceptions, this rule is golden:
!
?
), not implicitly unwrapped optionals (IUO) (!
)In other words, rather use:
var nameOfDaughter: String?
Instead of:
var nameOfDaughter: String!
if let
or guard let
Either unwrap variable like this:
if let nameOfDaughter = nameOfDaughter {
print("My daughters name is: \(nameOfDaughter)")
}
Or like this:
guard let nameOfDaughter = nameOfDaughter else { return }
print("My daughters name is: \(nameOfDaughter)")
This answer was intended to be concise, for full comprehension read accepted answer