NSData:writeToFile returning error "File doesn't exist"
<p>I'm currently using the following code to write a NSData in a subfolder of the documents folder.</p>

<pre><code>NSData* dataToSave=...;
NSFileManager* fileManager = [NSFileManager defaultManager];
NSString* documentsDir=[
    NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) 
    objectAtIndex:0];
NSString* desiredFolder=[documentsDir stringByAppendingPathComponent:@"MySubfolder"];
BOOL isDir;

if (![fileManager fileExistsAtPath:desiredFolder isDirectory:&amp;isDir]&amp;&amp;!isDir)
{
    NSError* error;
    [fileManager createDirectoryAtPath:desiredFolder 
         withIntermediateDirectories:NO attributes:nil error:&amp;error];
    if (error) {
        NSLog(@"Error%@", error.localizedDescription);
    }
}     
NSString* desiredFile=[desiredFolder stringByAppendingPathComponent:@"mfile.jpeg"];
if (![dataToSave writeToFile:desiredFile options:NSDataWritingAtomic error:&amp;error])
{
    NSLog(@"Error %@",error.localizedDescription);
    return NO;
}
</code></pre>

<p>It was working until I tested this config in "release mode" . There the NSData:writeToFile started to return <code>NO</code>, with the error: <code>The file 'myfile.jpeg´ doesn't exist</code>.</p>

<p>Where is the problem?</p>

<p>Thanks</p>