Note that there are some explanatory texts on larger screens.

plurals
  1. POCocoa: Why set 'nil' prior to the method call?
    primarykey
    data
    text
    <p>I have been working though the examples in <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/LowLevelFileMgmt/Articles/EnumADir.html#//apple_ref/doc/uid/20000783-BAJFBAAH" rel="nofollow">Using a Directory Enumerator</a> in the Apple Low-Level File sections.</p> <p>Here is a code snippet:</p> <pre><code>for (NSURL *url in enumerator) { // Error-checking is omitted for clarity. NSNumber *isDirectory = nil; [url getResourceValue:&amp;isDirectory forKey:NSURLIsDirectoryKey error:NULL]; if ([isDirectory boolValue]) { NSString *localizedName = nil; [url getResourceValue:&amp;localizedName forKey:NSURLLocalizedNameKey error:NULL]; NSNumber *isPackage = nil; [url getResourceValue:&amp;isPackage forKey:NSURLIsPackageKey error:NULL]; if ([isPackage boolValue]) { NSLog(@"Package at %@", localizedName); } else { NSLog(@"Directory at %@", localizedName); } } </code></pre> <p>}</p> <p>Why are <code>localizedName</code>, <code>isPackage</code>, and <code>isDirectory</code> being set to <code>nil</code> prior to the relevant calls to the <code>getResourceValue</code> method? Is this just an over abundance of caution or is this required? </p> <p>As <strong>I</strong> read <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html#//apple_ref/occ/instm/NSURL/fileReferenceURL" rel="nofollow">the docs</a> for <code>getResourceValue:forKey:error:</code> it seems redundant:</p> <blockquote> <p>Return Value YES if value is successfully populated; otherwise, NO.</p> <p>Discussion value is set to nil if the requested resource value is not defined for the URL. In this case, the method still returns YES.</p> </blockquote> <p>Am I missing something?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload