• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: JSONSerialization 'Garbage at end' error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JSONSerialization 'Garbage at end' error


  • Subject: Re: JSONSerialization 'Garbage at end' error
  • From: Kyle Sluder <email@hidden>
  • Date: Wed, 30 Apr 2014 18:12:15 -0700

On Wed, Apr 30, 2014, at 04:30 PM, Jens Alfke wrote:
>
> On Apr 30, 2014, at 4:00 PM, Jonathan Hull <email@hidden> wrote:
>
> > I also find that it is good practice to set variables returned by reference to nil before passing them.
> > NSError *error = nil;
> > Otherwise, they will contain garbage, and cannot reliably be tested to see if the value was set.
>
> That’s still not a good idea. If the call succeeds, it’s not guaranteed
> that the error value is unchanged. It might have been set to some
> intermediate error value, for example.
> If the call failed, the error will contain a valid value whether or not
> you initialized the variable, so there’s no need to initialize it.
>
> tl;dr: NEVER use the error value to determine whether or not the call
> succeeded. Use the return value for that. Only look at the error if the
> return value told you the call failed.

FWIW, there is at least one Apple API that requires you to check the
error rather than the return value. All Apple APIs should now be leaving
the error parameter alone in success cases. And with ARC, all object
pointers are initialized to nil, even local variables.

--Kyle Sluder

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >JSONSerialization 'Garbage at end' error (From: Diederik Meijer | Ten Horses <email@hidden>)
 >Re: JSONSerialization 'Garbage at end' error (From: Jens Alfke <email@hidden>)
 >Re: JSONSerialization 'Garbage at end' error (From: Andy Lee <email@hidden>)
 >Re: JSONSerialization 'Garbage at end' error (From: Jonathan Hull <email@hidden>)
 >Re: JSONSerialization 'Garbage at end' error (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: JSONSerialization 'Garbage at end' error
  • Next by Date: Re: Problem with distributed objects in GUI cocoa apps
  • Previous by thread: Re: JSONSerialization 'Garbage at end' error
  • Index(es):
    • Date
    • Thread