Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yeah @IBOutlets are generally the one thing that are allowed to be implicitly-unwrapped optionals. They go along with using storyboards & xibs files with Interface Builder. I agree that you really should just crash if you are attempting to access one and it is nil. Either you have done something completely incorrect with regards to initializing and accessing parts of your UI and want to catch that in development, or something has gone horribly, horribly, horribly with UIKit/AppKit and storyboard/xib files are not being loaded properly by the system.




> … you really should just crash if …

See my above/below comment.

A good tool for catching stuff during development, is the humble assert()[0]. We can use precondition()[1], to do the same thing, in ship code.

The main thing is, is to remain in control, as much as possible. Rather than let the PC leave the stack frame, throw the error immediately when it happens.

[0] https://docs.swift.org/swift-book/documentation/the-swift-pr...

[1] https://docs.swift.org/swift-book/documentation/the-swift-pr...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: