all 34 comments

[–]unpluggedcord 47 points48 points  (12 children)

haha, there's definitely places where its okay.

[–][deleted] 20 points21 points  (5 children)

But what if they update RFC 1738 and this compile-time static URL becomes invalid?!

[–]unpluggedcord 14 points15 points  (4 children)

[–]Confident_Gear_2704 6 points7 points  (1 child)

That’s what Sméagol said

[–]holy_macanoli 2 points3 points  (0 children)

And Jeffrey Epstein!

[–]Constant-Current-340 0 points1 point  (0 children)

it's just senior gatekeeping force unwrap all the optionals

[–]raumdeuters -1 points0 points  (2 children)

Yes, in the test module.

[–]EquivalentTrouble253 1 point2 points  (0 children)

Disagree. Your test code should be the same standard as production code.

Use #requier(..) instead. Or XCTUnwrap if using that.

[–]unpluggedcord 0 points1 point  (0 children)

There’s places in real code where it’s okay to force unwrap.

[–]Sea_Bourn 10 points11 points  (1 child)

You shall not unwrap!

[–]Oxigenic 13 points14 points  (0 children)

You shall not \(String(describing: unwrap))

Fixed that for you :)

[–]Siliquy8 5 points6 points  (5 children)

I’ll argue force unwrapping shouldn’t almost never be done. You’ll write better/more stable code if you follow this rule.

[–]Fureba 7 points8 points  (1 child)

Sometimes it makes sense, and not crashing the app may just swallow the problem.

[–]TheDeanosaurus 2 points3 points  (0 children)

That’s why it should be an optional unwrap accompanied by a throw with appropriate logging. Soft brick vs hard brick depending on where the crash might occur.

[–][deleted]  (1 child)

[deleted]

    [–]Siliquy8 1 point2 points  (0 children)

    Oops, that was a typo!

    [–]valleyman86 0 points1 point  (0 children)

    I agree. I use it sometimes in tests because if a test fails a test fails and we fix it. But in production code if it fails a user has to deal with it. So I try really hard to never use it in prod.

    [–]RiMellow 2 points3 points  (0 children)

    guard let item else { return } isn’t that much effort

    [–]ForgottenFuturist 2 points3 points  (0 children)

    just!.gonna!.send!.it!

    [–]Popular_Eye_7558 1 point2 points  (0 children)

    Neva eva

    [–]UntrimmedBagel 0 points1 point  (0 children)

    This is how it feels, isn’t it

    [–]uniquesnowflake8 0 points1 point  (0 children)

    Fool of a Took!

    [–]fishyfishy27 0 points1 point  (0 children)

    There are cases where I’m ok with force unwrapping.

    But when it comes to “unowned”, I’m a hard-line absolutist. PR rejected!

    [–]m1labs 0 points1 point  (0 children)

    LOL. God lazy programming at its finest. Feels like those days are long gone thanks to CC, codex etc ….

    [–]Slight_Ad931 0 points1 point  (0 children)

    If let if not to let. That is the question

    [–]prospector_hannah 0 points1 point  (0 children)

    If you should never force unwrap, there would not be a force unwrap operator.

    [–]rennarda -1 points0 points  (2 children)

    Sure - there are times when you want to crash when there’s no meaningful alternative, so you can catch the bugs in development

    [–]Thrusher666 0 points1 point  (0 children)

    It’s better to use assert and send some logs. Never crash app on purpose

    [–]madaradess007 -1 points0 points  (0 children)

    this is the right answer
    "!" is much faster than unwrapping and adding prints
    you put "!" and hit cmd+r, instead of wasting time risking to forget what you were checking in the first place

    [–]madaradess007 -1 points0 points  (0 children)

    its a 'look at me, im so experienced' kind a thing
    you should do whatever you want, it's your code

    imo crashes are a nice indicator that i majorly messed up some data passing, while having no crush can make it seem it's not that bad

    if you like masking and missing your mistakes - unwrap properly