views:

73

answers:

1

I am trying to write an nsdata to a file on my disk, I have the following code and it doesn't work, am i doing anything wrong?

Boolean result = [data writeToFile:@"/Users/aryaxt/Desktop/test2.avi" atomically:YES];

test2.avi doesn't exist, I am assuming that writeToFile would create it for me

+4  A: 

Try using :

NSError *error = nil;
path=@"/Users/aryaxt/Desktop/test2.avi";
[data writeToFile:path options:NSDataWritingAtomic error:&error];
NSLog(@"Write returned error: %@", [error localizedDescription]);

That'll tell you why the write is failing.

John Franklin
`error` should only be examined if the method returns `NO`. Foundation classes may put other objects or fake errors or even garbage in the error argument. (That's not to say that they *do*, but it's part of the programmer contract that they can, so be careful.)
Jonathan Grynspan