2 ms·
Strongly disagree with the "but worse" characteristic. As soon as you learn what "??" does, it's actually an improvement in readability in many cases. For examp
by eugeniub 7y ago
Strongly disagree with the "but worse" characteristic. As soon as you learn what "??" does, it's actually an improvement in readability in many cases. For example:
nameLabel.text = user?.name ?? "Guest"
This, as opposed to:
if let name = user?.name {
nameLabel.text = name
} else {
nameLabel.text = "Guest"
}
- bdisnainc 7y agoThat is because you apply pattern matching when it is not really useful here, on top of avoiding a simple ternary operator. In some languages, you simply write: if (user) nameLabel.text = user.name; else nameLabel.text = "Guest"; Or: nameLabel.text = user.name if user else "Guest" Or anything along those lines. Concise, clear, no need for an extra operator.