-10

I'm an Objective-C programmer and can only read basic Swift code, otherwise I would start this process myself instead of making this post.

As anyone active in the Swift/iOS tags knows, the number one issue posted is the "Unexpectedly found nil while unwrapping an Optional value" runtime error.

I think it would be very helpful if someone created a tag for this error and the tag description should include everything needed to properly find and fix the problem. This would need to include basic instructions for setting up symbolic breakpoints in Xcode since its mostly newer programmers running into this issue right from the start. Or perhaps a canonical answer should be posted with all the relevant details so the tag can reference that post.

I believe there may be a basic attempt already for such an answer.

I think the hardest part to start this process is coming up with a tag name for "Unexpectedly found nil while unwrapping an Optional value" that will seem obvious enough to anyone posting such a question.

Update

So it seems the idea of a tag for this isn't too popular. That's fine. So lets discuss other, better options for dealing with this.

Offer your ideas for improving Stack Overflow by helping solve this issue. What's the best way to help all of these Swift developers that don't understand debugging well enough to solve their all-too-common "Unexpectedly found nil while unwrapping an Optional value" error.

16
  • 3
    Canonical sounds good.
    – Zizouz212
    Mar 20, 2016 at 23:45
  • @Zizouz212 You say canonical, I say conical. :) Oops.
    – rmaddy
    Mar 20, 2016 at 23:47
  • What problem has stackoverflow.com/…? There are 898 results with at least an answer. Why would we need a tag specifically for an error?
    – Braiam
    Mar 20, 2016 at 23:55
  • 1
    @Braiam There are plenty of existing tags for various errors. Why not have one for the most common that includes useful debugging details? Examples: unrecongnized-selector, nsunknownkeyexception, exc-bad-access, etc.
    – rmaddy
    Mar 20, 2016 at 23:58
  • 3
    let needsCanonical: Bool? = nil; let goodIdea = needsCanonical!; fatalError("User didn't bother to search before asking")
    – user4151918
    Mar 21, 2016 at 0:43
  • 9
    EWWW... you are using crappy tags as example to create more crappy tags, no thanks. Is hard enough to get rid of the crappy tags we already have.
    – Braiam
    Mar 21, 2016 at 0:44
  • A canonical post would be good: this is the NPE of iOS. Perhaps matt can be persuaded to write one.
    – jscs
    Mar 21, 2016 at 1:22
  • 1
    @JoshCaswell The real issue is that people don't appear to know how to use a debugger. Until they advance past the basics (of debugging and properly unwrapping optionals), we're left closing a steady stream of duplicates. I imagine this is common to any language on SO. Since this would be a Swift-only solution, is language-by-language the best way to solve these types of programming errors?
    – user4151918
    Mar 21, 2016 at 1:53
  • It seems to the only way supported by the system and those who make it, @PetahChristian. I don't think it's the worst solution, either; the NPE canonical points out to those who have their questions closed that the proper solution to each specific problem is indeed debugging.
    – jscs
    Mar 21, 2016 at 2:11
  • @Braiam OK, then what is the best way to handle all of these questions?
    – rmaddy
    Mar 21, 2016 at 2:29
  • 1
    Well, I'm frankly hoping that the documentation beta would be a tool that could help novice programmers with programming issues like this. But I haven't gotten a beta invite yet and don't know what it can or will offer.
    – user4151918
    Mar 21, 2016 at 2:36
  • I doubt it. The most comprehensive and clear documentation will not prevent the incompetent from trying to use SO as a free debugging service. Mar 21, 2016 at 9:31
  • After all, as we all know from Hollywood, you make a computer do what you want it to by writing code. Efficiently organising data, designing tests and debugging are just some side-issue that does not matter to 'good programmers' who just type in stuff and it works correctly first time :( Mar 21, 2016 at 9:36
  • 2
    My favorite solution to this issue (and believe me I can't stand seeing these questions anymore either) would be a Community Wiki with the simplest question (not that far from @PetahChristian's satire actually) and several CW answers, each one explaining a possible and typical situation creating this error: IBOutlets not connected, forced-unwrapped values, etc. This way we could redirect almost everyone of these questions to this easy to find target.
    – Eric Aya
    Mar 21, 2016 at 12:35
  • @EricD. I like the idea of a CW question with several CW answers. Other situations might include as! forced downcasting failures, or not checking return values from methods which could return nil.
    – user4151918
    Mar 21, 2016 at 13:13

3 Answers 3

8

I would prefer having a nice canonical with one simple question stating the infamous error, maybe like:

I got the dreaded "Unexpectedly found nil while unwrapping an Optional value" error, what do I do now?

and having several answers, each one addressing the classic sources of this issue:

  • An IBOutlet is not properly connected in Interface Builder

  • An optional value has been "force unwrapped" with !

  • An optional value has been "force downcast" with as!

  • We don't know, here's how to debug your issue

etc.

Since it's a canonical, the question could also list every answer, so someone could quickly find the one corresponding to their specific issue.

In my mind, this canonical would have to be entirely Community Wiki, the question and the answers, to avoid any bias.

3
  • This seems like the best idea. How do we make it happen? Again, I don't know Swift so I'm not in a position to help get this effort off the ground.
    – rmaddy
    Mar 21, 2016 at 15:03
  • I'm ok to write this thing since it will be a CW and other Swift regulars will be able to fix/improve my answers. I don't promise anything, though, it's a lot of work. ;) Also, on a pragmatic level, I have no idea how to do this. Do I just create the page at once when I'm ready? How to avoid other users adding "normal" answers to the CW ones? I may have to ask a mod about all this.
    – Eric Aya
    Mar 21, 2016 at 15:20
  • 3
5

?

jtbandes has graciously made the question on his Q&A pair Community Wiki (thanks Undo), making both the Question and Answer on this post Community Wiki, eliminating bias.

We should be using this as the duplicate target related to any questions regarding finding nil when unwrapping an Optional value from now on.

originaluser2 has also merged their answer into jtbandes's from Duncan C's non-CW Q&A pair here.

1

I don't see what value such a tag would bring.

  • Given the frequent number of common questions, no one seems to search before asking. I doubt they'd even think to look for such a tag, so it wouldn't appear to benefit the OP at all.

  • It would take up one of five tag spots, to tag a "nil unwrapped Optional" canonical (or its duplicates).

    If a question already had 5 good tags, I don't see any advantage to replacing one of them with this proposed tag.

The only benefit I could see to such a tag would be to help those who close these questions to find the canonical, but I'd hope there would be a better way to do that (than needing to create a meta tag).

9
  • I suppose meta has a specific meaning here, like [discussion] or [bug]. But it doesn't seem to be a conventional tag, and does seem to describe the type of question/error. Isn't it merely more specific than a tag such as warnings?
    – user4151918
    Mar 21, 2016 at 1:30
  • Yeah, I'm not sure it would be really useful either. But it does refer to a thing that people have questions about.
    – jscs
    Mar 21, 2016 at 1:36
  • @JoshCaswell which move us to the next point, do we need a tag for each component people will ever talk about
    – Braiam
    Mar 21, 2016 at 1:39
  • We discussed that a couple of months ago, @Braiam: meta.stackoverflow.com/questions/314026
    – jscs
    Mar 21, 2016 at 2:12
  • We have a nullpointerexception tag.
    – jscs
    Mar 21, 2016 at 2:15
  • @PetahChristian I've added an update to my question. If using a tag isn't a good solution, what is? Ideally we can simply close all of these questions as a duplicate to the perfect answer. One that shows step by step how to debug and solve the problem without every one of these questions getting a one-off answer specific to the OP's code.
    – rmaddy
    Mar 21, 2016 at 2:29
  • @rmaddy Let me say I that I regularly see you editing tags. It's appreciated! :) And I hear you concerning one-offs. Everyone seems to need a specific answer, instead of realizing how to apply the general answer. But who would this proposed tag help? Those searching for answers? Those asking questions? Those who answer or close questions? Is there a particular value or benefit to creating this tag, apart from finding canonicals? Otherwise we're just classifying questions and it takes enough time as is to close or improve/answer questions.
    – user4151918
    Mar 21, 2016 at 2:34
  • @PetahChristian The idea of a tag was just that, an idea. I'm really looking for a good solution to the general problem. Somewhere (tag wiki, canonical answer, blog post, whatever) there needs to be a one-stop description of how to fix one's own "Unexpectedly found nil while unwrapping an Optional value" error. Then if someone fails to find it and posts a question, it can be quickly closed as a dupe of something useful. Whether a tag is good for this or not is only half of the point here.
    – rmaddy
    Mar 21, 2016 at 2:39
  • @rmaddy I'm hoping Documentation will be the in-house solution to the general problem. Yet it's too easy to get an answer here. Whether people fail to search, or search but fail to find a particular answer, there's no consequence unless/until they eventually get rate restricted. Either way, we need to educate people to stem the tide of less useful questions, and get those questions deleted after being closed (which is difficult if they've already been upvoted and answered). More gold badges, faster closing I suppose.
    – user4151918
    Mar 21, 2016 at 2:51

Not the answer you're looking for? Browse other questions tagged .