|
|
|
|
|
by stormbrew
3803 days ago
|
|
I don't think it's trying to be syntactically better than C++. It's an improvement in semantics. Once you unwrap an optional with "if let", it cannot cause an access violation. You seem to be insisting on using ! and then blaming the language for letting you shoot your foot off with it... |
|
the example you gave is like the following c++ code:
XXX *object = null;
if ((object = anotherpointer) != NULL)
{ ... }
The point is, ! is only useful, when it can detect null pointers during compiling time. but it doesn't.
the way ! is used, as suggested by your example, is also doable in C++, it is just a habit thing.
in c++, with good habit, you won't have problem. in Swift with bad habit, you will have the same problem.
then what good is !,