• 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
iPhone: NSFileManager/NSDirectoryEnumerator Crash?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

iPhone: NSFileManager/NSDirectoryEnumerator Crash?


  • Subject: iPhone: NSFileManager/NSDirectoryEnumerator Crash?
  • From: Jeffrey Walton <email@hidden>
  • Date: Wed, 09 Mar 2011 19:33:17 -0500

Hi All,

I've got a method that refreshes a list of files in a directory. The
code executes properly on the first invocation, but crashes on the
second invocation. The cause of the crash is walker = [fileManager
enumeratorAtPath:directory].

Any ideas on the cause? I experience the crash with both methods of
retrieving the file manager. Are there known issues with
enumeratorAtPath?

Jeff

    NSString* directory = nil;
    NSFileManager* fileManager = nil;
    NSDirectoryEnumerator* walker = nil

    directory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    if(directory == nil)
        /* handle error and exit */

    // fileManager = [NSFileManager defaultManager];
    fileManager = [[NSFileManager alloc] init];
    if(fileManager == nil)
        /* handle error and exit */

    walker = [fileManager enumeratorAtPath:directory];
    if(walker == nil)
        /* handle error and exit */

    NSString* file = nil;
    while((file = [walker nextObject]) != nil)
    {
        BOOL isDirectory = YES;
        if([fileManager fileExistsAtPath:file
isDirectory:&isDirectory] && !isDirectory)
            [files addObject:file];
    }

    ...

    [fileManager release];

*****

According to 'NSFileManager Class Reference'
(http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html):

    In iOS and Mac OS X v 10.5 and later you should consider
    using [[NSFileManager alloc] init] rather than the singleton
    method defaultManager. Instances of NSFileManager are
    considered thread-safe when created using
    [[NSFileManager alloc] init].
_______________________________________________

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: iPhone: NSFileManager/NSDirectoryEnumerator Crash?
      • From: Andreas Grosam <email@hidden>
    • Re: iPhone: NSFileManager/NSDirectoryEnumerator Crash?
      • From: Quincey Morris <email@hidden>
  • Prev by Date: NSApplicationPresentation not honored when asking for admin rights ??
  • Next by Date: Soap message with attachment
  • Previous by thread: NSApplicationPresentation not honored when asking for admin rights ??
  • Next by thread: Re: iPhone: NSFileManager/NSDirectoryEnumerator Crash?
  • Index(es):
    • Date
    • Thread