Working with the NSData Class

When working with files, you often need to read data into a temporary storage area, often called a buffer. When collecting data for subsequent output to a file, a storage area is also often used. Foundation’s NSData class provides an easy way to set up a buffer, read the contents of the file into it, or write the contents of a buffer out to a file. And just in case you’re wondering, for a 32-bit application, an NSDATA buffer can store up to 2GB. For a 64-bit application, it can hold up to 8EB (that’s exabytes) or 8 billion gigabytes of data!

As you would expect, you can define either immutable (NSData) or mutable (NSMutableData) storage areas. We introduce methods from this class in this chapter and in succeeding ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.