Instance Method

readData(ofLength:)

Synchronously reads data up to the specified number of bytes.

Declaration

func readData(ofLength length: Int) -> Data

Parameters

length

The number of bytes to read from the receiver.

Return Value

The data available through the receiver up to a maximum of length bytes, or the maximum size that can be represented by an NSData object, whichever is the smaller.

Discussion

If the receiver is a file, this method returns the data obtained by reading length bytes starting at the current file pointer. If length bytes are not available, this method returns the data from the current file pointer to the end of the file. If the receiver is a communications channel, the method reads up to length bytes from the channel. Returns an empty NSData object if the file is positioned at the end of the file or if an end-of-file indicator is returned on a communications channel. This method raises NSFileHandleOperationException if attempts to determine the file-handle type fail or if attempts to read from the file or channel fail.

See Also

Reading from a File Handle

var availableData: Data

The data currently available in the receiver.

func readDataToEndOfFile() -> Data

Synchronously reads the available data up to the end of file or maximum number of bytes.

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