Instance Method

subdata(with:)

Returns a data object containing the receiver’s bytes that fall within the limits specified by a given range.

Declaration

func subdata(with range: NSRange) -> Data

Parameters

range

The range in the receiver from which to get the data. The range must not exceed the bounds of the receiver.

Return Value

A data object containing the receiver’s bytes that fall within the limits specified by range. If range isn’t within the receiver’s range of bytes, raises NSRangeException.

Discussion

A sample using this method can be found in Working With Binary Data.

See Also

Finding Data

func range(of: Data, options: NSData.SearchOptions = [], in: NSRange)

Finds and returns the range of the first occurrence of the given data, within the given range, subject to given options.

struct NSData.SearchOptions

Options for method used to search data objects.