• 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
-dataWithContentsOfFile returning a NSData object, but no file exists?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

-dataWithContentsOfFile returning a NSData object, but no file exists?


  • Subject: -dataWithContentsOfFile returning a NSData object, but no file exists?
  • From: email@hidden
  • Date: Tue, 13 Dec 2005 23:18:54 -0800

I'm running some code that basically boils down to the following lines:

imageData = [NSData dataWithContentsOfFile:filepath];
if (imageData == nil) {
imageData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForImageResource:@"loading.png"]];
}

Unfortunately, in some cases (but not all), what I'm getting is an NSData object that has zero bytes of Data. If I go to the directory path specified in the "filepath" variable, there is no file - which I figured should return a nil object instead of a valid object with zero bytes of data.

But what's weird is that elsewhere in my program, I'm doing this:

if (![[NSFileManager defaultManager] fileExistsAtPath:photoFilePath]) {
NSData *photoData = [NSData dataWithContentsOfURL:url];
return [photoData writeToFile:cacheFilePath atomically:NO];

If the a file doesn't already exist, it should write it out. Both of the above pieces of code run over and over again through a batch of objects - loading from a URL and writing to a file if it doesn't exist, and then elsewhere trying to read that data.

For some reason, NSFileManager is saying that fileExistsAtPath is true, NSData is not returning nil, but is returning an NSData object with zero bytes of data, but according to the Finder and spotlight, the file does not exist.

This problem continues even if I quit and restart my program.

Any ideas where I should look? Is there some sort of caching that goes on in NSFileManager and/or NSData that I can somehow reset?

thanks,
Blake
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Prev by Date: Re: [COREDATA] Assign NSManagedObject to persistent store
  • Next by Date: Re: Getting the arguments of methods in other frameworks (from GDB)
  • Previous by thread: Re: Cocoa timer - Using NSTimer or an alternative for timer program
  • Next by thread: CoreData, Two Nibs and Bindings
  • Index(es):
    • Date
    • Thread