Data

public extension Data

This extension adds the ability to extract data from a Data instance, cast into various types.

  • This method allows a Data instance to be cast into various standard types.

    NOTE This is not a “safe” method! It circumvents Swift’s safety bumpers, and could get you in trouble if you don’t use trivial types!

    Declaration

    Swift

    @discardableResult
    mutating func castInto<T>(_ inValue: inout T, offsetInBytes inOffsetInBytes: UInt = 0) -> Int

    Parameters

    inValue

    This is an inout parameter, and the type will be used to determine the cast.

    offsetInBytes

    The number of bytes “into” the data we will go to perform the interpretation. This is an unsigned, 0-based integer. Default is 0 (can be ignored).

    Return Value

    The number of bytes read. Can be ignored.