The easiest way to write NSData to a file

papr picture papr · Mar 24, 2009 · Viewed 84.1k times · Source
NSData *data;
data = [self fillInSomeStrangeBytes];

My question is now how I can write this data on the easiest way to an file.

(I've already an NSURL file://localhost/Users/Coding/Library/Application%20Support/App/file.strangebytes)

Answer

Alex picture Alex · Mar 24, 2009

NSData has a method called writeToURL:atomically: that does exactly what you want to do. Look in the documentation for NSData to see how to use it.