NSFileHandle

When reading a file, Cocoa programmers often read in an entire file and pack it into an NSData or NSString before parsing it. When writing a file, Cocoa programmers usually create a complete NSData or NSString which is then written to the file system. Sometimes you want more control over reading from and writing to files. For example, you might read a file just until you find what you want and then close it. For more control over reading and writing from files, you use an NSFileHandle object.

An NSFileHandle is used for reading and writing files. Some of the reading methods are blocking (that is, the application stops and waits for the data to become available), and others are non-blocking. We’ll discuss the non-blocking methods ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide 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.