• 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: NSURL bookmark error return
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSURL bookmark error return


  • Subject: Re: NSURL bookmark error return
  • From: Mike Abdullah <email@hidden>
  • Date: Wed, 19 Dec 2012 00:11:46 +0000

On 18 Dec 2012, at 08:37, Quincey Morris <email@hidden> wrote:

> Was there a thread recently that listed a couple of Cocoa frameworks methods that mis-handle the NSError** parameter? What were those methods? The reason I ask is that the general file system documentation for dealing with bookmarks:
>
>> https://developer.apple.com/library/mac/#documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/AccessingFilesandDirectories/AccessingFilesandDirectories.html#//apple_ref/doc/uid/TP40010672-CH3-SW10
>
>
> gives this code fragment:
>
>> - (NSData*)bookmarkForURL:(NSURL*)url {
>>    NSError* theError = nil;
>>    NSData* bookmark = [url bookmarkDataWithOptions:NSURLBookmarkCreationSuitableForBookmarkFile
>>                                            includingResourceValuesForKeys:nil
>>                                            relativeToURL:nil
>>                                            error:&theError];
>>    if (theError || (bookmark == nil)) {
>>        // Handle any errors.
>>        return nil;
>>    }
>>    return bookmark;
>> }
>
> which doesn't follow the rules for testing for errors. The succeeding fragment is even worse:
>
>> - (NSURL*)urlForBookmark:(NSData*)bookmark {
>>    BOOL bookmarkIsStale = NO;
>>    NSError* theError = nil;
>>    NSURL* bookmarkURL = [NSURL URLByResolvingBookmarkData:bookmark
>>                                            options:NSURLBookmarkResolutionWithoutUI
>>                                            relativeToURL:nil
>>                                            bookmarkDataIsStale:&bookmarkIsStale
>>                                            error:&theError];
>>
>>    if (bookmarkIsStale || (theError != nil)) {
>>        // Handle any errors
>>        return nil;
>>    }
>>    return bookmarkURL;
>> }
>
> since it doesn't even check the returned value.
>
> Is this a documentation error, or is the documentation explaining how to code around a frameworks deficiency?
>
> BTW the NSURL class reference documentation doesn't say anything about this. It doesn't even mention nil return values.

That sample code scares me. I wrote this recently, if it helps:
http://www.mikeabdullah.net/nsurl-bookmark-error-handling.html


_______________________________________________

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

  • Follow-Ups:
    • Re: NSURL bookmark error return
      • From: Quincey Morris <email@hidden>
References: 
 >NSURL bookmark error return (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Compiler can't find method declared in protocol
  • Next by Date: Re: NSURL bookmark error return
  • Previous by thread: NSURL bookmark error return
  • Next by thread: Re: NSURL bookmark error return
  • Index(es):
    • Date
    • Thread