• 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: Why Don't Cocoa's (Un)Archiving Methods return Errors?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?


  • Subject: Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?
  • From: Sean McBride <email@hidden>
  • Date: Fri, 05 Aug 2011 10:52:35 -0400
  • Organization: Rogue Research Inc.

On Thu, 28 Jul 2011 23:24:54 -0700, Jerry Krinock said:

>With each major update of Mac OS X, Apple updates more classes to return
>proper NSErrors, deprecating methods which either don't give errors or
>give outmoded error representations.
>
>But what about NSKeyedArchiver and NSKeyedUnarchiver, in particular
>these methods…
>
>+[NSKeyedArchiver archivedDataWithRootObject:]
>+[NSKeyedUnarchiver unarchiveObjectWithFile:]
>
>-unarchiveObjectWithFile: takes a file, for heaven's sake.  If someone
>has messed with the file, eek, it raises an exception.  I generally
>enclose these methods in @try{} to avoid that.  Very primitive!
>
>Does anyone know why these methods not marked for deprecation?  Is there
>a reason why we don't we have 21st-century archive/unarchive methods
>that return errors instead of raise exceptions?

They also haven't been updated to take URLs instead of paths. :(

Of all the replies, no one seemed to mention that you can use unarchiveObjectWithData: instead.  Use a modern API (with NSError) to read your file, then if successful, pass the NSData on.  That helps a little, at least for file system errors.

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada
_______________________________________________

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

  • Prev by Date: Re: NSFileManager - a cautionary tale
  • Next by Date: Re: view:(QTMovieView *)view willDisplayImage:
  • Previous by thread: Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?
  • Next by thread: Re: core data migration - delete old store
  • Index(es):
    • Date
    • Thread