Data

public protocol Data

Data is an object that represents a set of custom data fields (key/value pairs) defined in the formats section of the device model. The custom data is sent by calling the submit method.

The set method returns the Data instance to allow the data fields to be set in fluent style.

  • Set the value of a field in the Data. The fields are determined by the format given when the Data is created. The value is validated according to the constraints in the format. If the value is not valid, a ClientError.argument exception is thrown.

    All fields defined in the format that are not “optional” must be set before calling submit()

    Throws

    ClientError.argument if field is nil or value is not valid

    Declaration

    Swift

    func set(field: String, value: AnyObject) throws -> Data

    Parameters

    field

    name of a field from the custom data format

    value

    the value to set

    Return Value

    Data object that can be used for function chaining

  • This method is used to actually send the custom data fields to the server. All mandatory fields (according to the device model definition) must be set before sending, otherwise an error will be thrown. Any error that can arise while sending will be handled by the VirtualDevice.onError handler, if set.

    After a successful send all the values are reset so to send again the values must be set again.

    Throws

    • ClientError.argument if a required field is not set
    • ClientError.network if a MessageDispatcher cannot be obtained.

    Declaration

    Swift

    func submit() throws
  • Set a callback that is invoked if an error occurs when submitting the Data. The callback may be nil, which will un-set the callback.

    Declaration

    Swift

    func setOnError(callback: ((ErrorEvent) -> ())?)

    Parameters

    callback

    a callback to invoke, or nil