A programmer who uses the BANG! is saying, “At this point in the code, this value will never be
nil, or will always downcast to the expected type.” Why is this important? Several reasons. For one, any time you have to deal with optionals, you have to deal with the possibility that the value will be
nil. This creates an alternate code path and you have to decide what to do with it. If you’re not going to crash, what are you going to do? Throw an exception? Who will handle it? Log the error to the console? Who will ever see it? Silently fail and do nothing? What if the caller always expects correct behavior? Then you’ve just swept a bug under the rug.
Published under the following tags: link, swift, optional, bang-operator, force-unwraping
No comments received yet.
- Write your comment on your on page and link it to this page with the following link:
- Insert the permalink to your post in the form below
- Submit the form
Alternatively you can reach me by email to: firstname.lastname@example.org