Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The easiest way to write NSData to a file

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)

like image 227
papr Avatar asked Mar 24 '09 20:03

papr


People also ask

What is NSData type?

A static byte buffer that bridges to Data ; use NSData when you need reference semantics or other Foundation-specific behavior.

What is NS Data?

Data and NSData are types used to interact with raw binary data. They're commonly used to hold raw data more complex than single strings, integers, bools, and so on.

What is NSMutableData in Swift?

NSMutableData is “toll-free bridged” with its Core Foundation counterpart, CFData . See Toll-Free Bridging for more information on toll-free bridging. Important. The Swift overlay to the Foundation framework provides the Data structure, which bridges to the NSMutableData class and its immutable superclass NSData .


1 Answers

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.

like image 137
Alex Avatar answered Nov 16 '22 20:11

Alex