Edit to add: And unless something has changed since I last tried it, you can also just shadow blah so that inside that scope you're referring to the unwrapped one:
if let blah = blah { /* use blah here, it's unwrapped */ }
It looks kind of silly, but I have used it where there was no better name for the unwrapped value.I still don't understand the point of ! and ?
less is more, swift ought to know.
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 !,
! is there for the small number of cases where that's not possible. And it makes it much more obvious where you've got a potential problem, because the '!' is a literal code smell. You can't really do that with c++.