Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8989691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:19:25+00:00 2026-06-15T22:19:25+00:00

I’m experiencing a very weird issue, which after several months of testing just happened

  • 0

I’m experiencing a very weird issue, which after several months of testing just happened to pop up as I was about to submit the app.

I have the folliwing method which takes some JSON data and converts it to a dictionary:

NSError *e;
NSMutableDictionary *result= [NSJSONSerialization JSONObjectWithData:jsonData 
                              options:NSJSONReadingMutableContainers error:&e];
if (e != nil) return nil;

For the past few months, this method has been used non stop, with absolutely no problems. But just today, it just stopped working. It now always results in an error (with no description; just a non-nill error).

It turns out, all I had to do to fix the problem was set NSError *e = nil;. I thought it was just good practice to do that, not absolutely critical. This scares me. I wonder how many times else I’m doing this in my code. Can anyone explain what could possibly be going on?

Also, I am using ARC, which I guess makes it even stranger that this is happening.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:19:27+00:00Added an answer on June 15, 2026 at 10:19 pm

    Your code is wrong, and so is your fix. What you need to do is say

    if (result == nil) {
        // an error occurred, and the NSError* variable can now be consulted
    }
    

    If result is anything besides nil, then you’re not allowed to assume anything about the contents of e.


    The basic reason here is that APIs that have NSError** return values are not required to put anything in that spot unless the API returned an error. Typically this means that in the non-error case they don’t modify the value at all, so whatever you had in your e variable before is what you have after. If your code is compiled without ARC, your e variable will have garbage from the stack in it. Under ARC it will be initialized to nil, but I’m guessing you’re not under ARC for reasons I will get to.

    However, it’s more complicated than this. Even if the method does not return an error, it may still have modified the NSError** value anyway. The simple example is if this method calls another method, passing the same NSError** into that method, and then recovers from the error and returns a success value instead. Yet the second method may have populated your NSError* variable with an error that is no longer valid.

    Now, the reason why I think your code isn’t ARC is because, to the best of my knowledge, all of the Cocoa APIs these days take pains to not modify the NSError** value unless an error occurred. This is in line with the new guidelines established a year or two ago (it was either at the beginning of 2011 or 2012, I forget which) that say that methods that have an NSError** parameter should only modify it in the error case. This is intended to allow code that says NSError *e = nil; [foo callAPIWithError:e]; if (e) ... to work, even though that’s not actually following the rules of NSError APIs, purely as a practical matter to be more resilient in the face of incorrect code. And since ARC nils out all automatic variables with an object type, your crash suggests that e was not nilled out and therefore you’re not in ARC.

    However, despite what I just said in the above paragraph, you still should not assume that any NSError-enabled API will leave the NSError value alone when no error is thrown. The current guidelines for implementing such APIs do say that should be true, but that’s not a hard requirement. Any code written before those guidelines may not behave that way, and any code written after the guidelines may just ignore them. The rules for calling an NSError-enabled API continue to state that the return value of the API must be consulted, and the NSError* variable may only be observed if the return value indicated an error occurred.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I've tracked down a weird MySQL problem to the two different ways I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.