Error al guardar los datos en el directorio de caché (iPhone)

Estoy tratando de guardar imágenes usando el siguiente código:

<code>- (void)writeData{

    if(cacheFileName==nil)
        return;
    if(cacheDirectoryPath==nil)
        return;


    if (![[NSFileManager defaultManager] fileExistsAtPath:[self filePath]]) {        

        NSData *imageData = UIImageJPEGRepresentation(self.image, 0.9);

        NSError *writeError= nil;

        BOOL didWrite =  [imageData writeToFile:[self filePath] options:NSAtomicWrite error:&writeError];

        if(writeError)
            NSLog([writeError localizedDescription]);

        if(didWrite)
            NSLog(@"image saved");
        else
            NSLog(@"image not saved");


    }
}





 - (NSString *)filePath{

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
    NSString *cacheDirectory = [paths objectAtIndex:0]; 
    NSString *filename = [cacheDirectory stringByAppendingPathComponent:cacheDirectoryPath]; 
    filename = [filename stringByAppendingPathComponent:cacheFileName]; 
    NSLog(filename);

    return filename;

}
</code>

Me sale un error:

<code>2009-06-23 16:39:19.740 XXX[33454:20b] Operation could not be completed. (Cocoa error 4.)
</code>

Miré esto y veo que el error tiene el siguiente significado:

<code> NSFileNoSuchFileError = 4,                 // Attempt to do a file system operation on a non-existent file
</code>

Lo que no tiene sentido ya que el archivo no debería existir.

He intentado escribir la representación png y usar el método de conveniencia:

<code>- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag
</code>

Estoy utilizando un código similar para guardar errores, y funcionan bien. No estoy seguro de cual es el problema. ¿Algunas ideas?

Respuestas a la pregunta(1)

Su respuesta a la pregunta