67

This is not an attempt to appeal the decisions of the community, I just want to become a better stackoverflower...

I posted a question (Now edited, so no need to go looking for it) asking how to convert an NSString to an int. Within moments, it had several downvotes.

quick Swift question:

So, I have an app that needs to convert from NSString to an integer. Here's what I tried -

var variable = (NSString(data:data, encoding:NSUTF8StringEncoding)) exampeStruct.otherVariable = (variable).toInt() I would expect it to set exampleStruct.otherVariable to an int value of the NSString, but it gives the error "NSString does not have a member toInt?"

What is the proper way to convert nsstring to int?

It was soon closed as off topic. I've looked through the How to Ask Questions thing in help center, and I can't seem to find what I missed...

Search, and Research

This was done. First, I tried it by guessing, then next I went to google. As you know, google displays result differently for everyone, but in case you need to check, there was no help while researching this way.

Write a title that summarizes the specific problem

"NSString to Integer" would seem to fit this rule...

Introduce the problem before you post any code

Yup! "...Convert from nsstring to integer..." Would seem to do that.

Help others reproduce the problem

I included the smallest amount of code necessary to reproduce the problem.

Include all relevant tags

ios xcode swift nsstring all seem to be relevant

Proof-read before posting!

Done! Not saying it was perfect, but it was proofread.

Post the question and respond to feedback

I interacted with the commentors...

Look for help asking for help

This is this post :D

It was also closed for being a

a problem that can no longer be reproduced or a simple typographical error

It was a reproducible (I gave code!) debugging question. There was no typos in the code, as far as I am aware...

As well as...

"Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers.

It had a desired behavior/specific problem/problem statement "Convert from NSString to an integer". It had code that reproduced it.

So, having tried in vain to figure out what I did wrong, any chance you can tell me? Thanks for your time, and apologies for probably a basic question. Again, I have no issues with what the community decided to do, I just want to learn.

15
  • 6
    I don't agree with the close reason, but I see a couple of what could be dupe questions just by googling "Swift convert NSString to int", in the first 3 results are 2 SO questions which seem to address your question, namely stackoverflow.com/questions/24019236/… and stackoverflow.com/questions/24153042/…. Mind you I don't know swift that much, maybe you're trying something different.
    – Patrice
    Commented Oct 31, 2014 at 13:13
  • 2
    I also don't know Swift, but seems like using the word "convert" would be useful when trying to find information on how to convert from one type to another in a Google search. Commented Oct 31, 2014 at 13:43
  • @rocket101: Can you look also to this point? meta.stackoverflow.com/questions/275810/…
    – Revious
    Commented Oct 31, 2014 at 13:45
  • 52
    Wow. This has got to be one of the best "why was my post closed?" meta questions I've ever seen. Kudos for not ranting, accepting that there could be something wrong with your question instead of blaming the community, checking the help center, and actually reading it! My faith in humanity has been restored. Commented Oct 31, 2014 at 15:39
  • 2
    Please don't use the Xcode tag unless you're asking about the IDE itself.
    – NobodyNada
    Commented Oct 31, 2014 at 15:47
  • 2
    @AnthonyGrist This is why I get upset about the snide and insulting comments I sometimes see about questioners not looking for answers themselves. Sometimes people have tried, but are not as good at guessing the correct search terms to type in.
    – ajb
    Commented Oct 31, 2014 at 17:43
  • I think the term is "Stacker" :-) Commented Oct 31, 2014 at 22:44
  • 2
    Sadly such things are common on SO Commented Nov 1, 2014 at 15:48
  • 6
    Minor hint: avoid noisy, irrelevant statements like "quick Swift question". What does "quick question" even mean? And the fact that your post is a question can be clearly seen by just looking at it (that's a plus, because nowadays most questions don't really look like questions and it's hard to decide what are they).
    – BartoszKP
    Commented Nov 1, 2014 at 15:49
  • 2
    I'm disappointed by the general response of the stackoverflow community to the original question. I think a more supportive approach to help improve/clarify the question, rather than closing it, would be more beneficial to everyone.
    – Dean
    Commented Nov 2, 2014 at 22:16
  • @ajb Sure, sometimes things aren't easy to find unless you know the exact combination of terms. However, I see a lot of examples where I can literally copy/paste the key point of the question into Google and find the answer trivially. I don't really think being bad at using search engines is an excuse; if you've legitimately tried to find information and haven't managed to do so, posting at least some of the combinations of search terms would go a long way towards actually demonstrating that. Commented Nov 3, 2014 at 14:21
  • @AnthonyGrist I did that - see above post.
    – rocket101
    Commented Nov 3, 2014 at 14:28
  • @AnthonyGrist If you post the specific terms you googled for, does that somehow make your question a better question? No, because that information is just noise, especially if you didn't actually find what you were looking for using those search terms. So what if you searched for "unicorns" and didn't get any results about waffles? See Should Stack Overflow (and Stack Exchange in general) be awarding “A”s for Effort? Commented Nov 3, 2014 at 17:40
  • @BartoszKP Thanks for the feedback - will refrain from such statements accordingly.
    – rocket101
    Commented Nov 3, 2014 at 20:38
  • @NobodyNada Didn't know that, will do. Thanks!
    – rocket101
    Commented Nov 3, 2014 at 20:39

2 Answers 2

34

Your question wasn't closed because it was basic (at least I hope not). It appears to have been closed incorrectly (at least for the reason given). It doesn't appear from the comments or the question itself that it is just a typographical error.

If the question was closed because "No Research was done", that has never been a reason to close a question. It's a reason to downvote, but not close.

As far as making your question more better, here are some things you could have done to help your question be better received:

  • Spend time on the formatting of the question. As an example, your question looked like this:

original question

With just a few minutes, you could have made it look like this:

How do I convert an NSString to an integer using Swift?

I need to convert an NSString to an integer in Swift:

Here's the current code I'm using; it doesn't work:

 var variable = (NSString(data:data, encoding:NSUTF8StringEncoding))
 exampeStruct.otherVariable = (variable).intValue

I expect it to set exampleStruct.otherVariable to an int value of the NSString, but I get the following error:

"Cannot convert the expression's type () to type Float"

How do I convert an NSString to int in Swift?

Appearance matters. Your question had nothing wrong with it other than you didn't take the time to make it look good. That's important on Stack Overflow. It shows that you respect our time and you respect the fact that this question will be around for a while.

Another tip is to make your question title what you'd search for if you were on Google. Would you search for "NsString to Integer"? Or would you search for "Converting NSString to Integer in Swift"?

Your title isn't just for you, it's for the answerers and most importantly the people who have the problem following you.

7
  • +1 Thanks so much... OK if no, but would you mind taking a a quick look at my edited post? I tried to edit it based on your suggestions... did it work?
    – rocket101
    Commented Oct 31, 2014 at 13:30
  • Just saw the edits... thanks so much. Really kind of you.
    – rocket101
    Commented Oct 31, 2014 at 13:41
  • 3
    "Your question had nothing wrong with it other than you didn't take the time to make it look good." Andrew Medico disagrees. Commented Oct 31, 2014 at 15:41
  • @thissuitisblacknot the problem with closing it for the reason it was closed is that they used the wrong reason. "Can no longer be reproduced" means the code is runnable but the error is not present. It does not mean, "the OP has not given us enough information to reproduce the problem." That's what off topic->close "why isn't this code working" means.
    – George Stocker Mod
    Commented Oct 31, 2014 at 16:57
  • 1
    Regardless of the close reason used, your statement that nothing was wrong with the question besides the formatting seems inaccurate based on Andrew's answer (I've never used Swift so I don't know). Commented Oct 31, 2014 at 17:05
  • 1
    I'm not exactly sure how it went down (the system only shows that the question was closed as "off-topic" and no longer shows the individual votes) but it looks like the OP is saying that the close votes were split ("It was closed as ... As well as ..."). The "debugging help" reason definitely applies. The "can no longer be reproduced / typo" may have been used in good faith (maybe the conversion function name was simply mis-spelled? I don't know Swift) or maybe it was a mis-click.
    – nobody
    Commented Oct 31, 2014 at 17:27
  • In my experience a lot of people do close questions because "no research was done", whether it should be done or not. Maybe they miss the old close reason.
    – simonzack
    Commented Nov 7, 2014 at 14:53
28

For clarification on "reproducible", see https://stackoverflow.com/help/mcve and http://sscce.org. The code you posted references several variables about which you have told us nothing (exampleStruct, data). It cannot be compiled and executed by another user to actually reproduce your issue. Your example should contain all the elements necessary for another user to copy and paste your code into an editor/IDE, compile it, and reproduce the problem you're describing.

5
  • 1
    As I mention in another comment, the wrong close reason was used to indicate the problem does not have the information needed to reproduce it.
    – George Stocker Mod
    Commented Oct 31, 2014 at 16:58
  • 1
    I think that the close votes were split, and in that case I agree that the "can no longer be reproduced" reason probably did not really apply.
    – nobody
    Commented Oct 31, 2014 at 17:38
  • 1
    SO would be a better place if every question that ought to have an MCVE, had one. The hammer is simply not large enough. Commented Nov 1, 2014 at 5:11
  • 1
    I've pasted code tons of times with stuff like classes attached to the problem function (such as Connector::Init()) without including the actual class from the header. Going by your definition, almost all questions here would have too many lines of code to be easily readable.
    – AStopher
    Commented Nov 1, 2014 at 11:13
  • 15
    @cybermonkey: Not true at all. You are supposed to narrow down the problem before posting. It's called debugging. Then your testcase becomes complete and minimal. I'm sorry to hear that you've violated this "tons of times": I'm going to have to go through all your questions and close them now! Commented Nov 1, 2014 at 15:41

You must log in to answer this question.

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