Confirming order of operations

Hmm. What style, exactly?

If it were this:

        weakProperty!.variable = weakProperty!.otherVariable

then I can see a stylistic argument (avoiding a noisy test for a condition that isn't going to be handled anyway).

If it were this (if it would compile):

        weakProperty?.variable = weakProperty?.otherVariable

then I can see another stylistic argument (concisely testing a condition "inline").

But this:

        weakProperty?.variable = weakProperty!.otherVariable

has the appearance of using "!" simply to shut the compiler up, or treating optionals as a nuisance quirk of Swift that is best ignored. That may not be the intention, but it reads that way. We've been there already: Resolved: Insert "!" is a bad fixit

2 Likes