Instance Property


The block to use for reading the contents of the file handle asynchronously.


var readabilityHandler: ((FileHandle) -> Void)? { get set }


The default value of this property is nil. Assigning a valid Block object to this property creates a dispatch source for reading the contents of the file or socket. Your block is submitted to the file handle’s dispatch queue when there is data to read. When reading a file, your handler block is typically executed repeatedly until the entire contents of the file have been read. When reading data from a socket, your handler block is executed whenever there is data on the socket waiting to be read.

The block you provide must accept a single parameter that is the current file handle. The return type of your block should be void.

To stop reading the file or socket, set the value of this property to nil. Doing so cancels the dispatch source and cleans up the file handle’s structures appropriately.

See Also

Reading and Writing Using Blocks

var writeabilityHandler: ((FileHandle) -> Void)?

The block to use for writing the contents of the file handle asynchronously.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software