Instance Method


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


func subdata(with range: NSRange) -> Data



The range in the receiver from which to get the data. If this range is not within the data object's range of bytes, rangeException is raised.

Return Value

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


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) -> 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.