Saturday, April 27, 2013

NSFileHandle fileHandleWithNullDevice example ios


fileHandleWithNullDevice

Returns a file handle associated with a null device.
+ (id)fileHandleWithNullDevice
Return Value
A file handle associated with a null device.
Discussion of [NSFileHandle fileHandleWithNullDevice]
You can use null-device file handles as “placeholders” for standard-device file handles or in collection objects to avoid exceptions and other errors resulting from messages being sent to invalid file handles. Read messages sent to a null-device file handle return an end-of-file indicator (an empty NSData object) rather than raise an exception. Write messages are no-ops, whereas fileDescriptor returns an illegal value. Other methods are no-ops or return “sensible” values.[NSFileHandle fileHandleWithNullDevice]
When using this method to create a file handle object, the file handle owns its associated file descriptor and is responsible for closing it.
Example of [NSFileHandle fileHandleWithNullDevice]

NSFileHandle *nullFileHandle = [NSFileHandle fileHandleWithNullDevice];
[task setStandardOutput:nullFileHandle];
[task setStandardError:nullFileHandle];