DataType
public class DataType<T> : DataTypeProtocol
The implementation of a DataType uses the DataTypeProtocol to convert input to a strongly typed data and print it if needed
-
The existing type to map to an internal one
Declaration
Swift
let type: T.Type -
Array of literals that tell the framework how to transform certain types to an internal
DataTyperepresentationDeclaration
Swift
let literals: [Literal<T>] -
To be able to bridge the outside world effectively, it needs to provide an already existing Swift or user-defined type. This can be class, struct, enum, or anything else, for example, block or function (which is not recommended). The literals tell the framework which strings can be represented in the given data type The last print block is used to convert the value of any DataType to a string value. It does not need to be unique or always the same for the same input values.
Declaration
Swift
public init (type: T.Type, literals: [Literal<T>], print: @escaping (_ body: DataTypeBody<T>) -> String)Parameters
typeThe existing type to map to an internal one
literalsArray of literals that tell the framework how to transform certain types to an internal
DataTyperepresentationprintA method to convert an internal representation to strings - for debugging and output representation purposes
bodyStruct containing the value and a printer instance
-
For the conversion it uses the registered literals, to be able to process the input and return an existing type
Declaration
Swift
public func convert(input: String, interpreter: TypedInterpreter) -> Any?Parameters
inputThe input to convert as a
DataTypevalueinterpreterAn interpreter instance if the content needs any further evaluation
Return Value
The value of the
DataTypeornilif it cannot be processed -
This is a convenience method, for debugging and value printing purposes, which can return a string from the current data type. It does not need to be unique or always the same for the same input values.
Declaration
Swift
public func print(value input: Any, printer: Printer) -> String?Parameters
valueAny value that is a valid
DataTypeprinterAn interpreter instance if the content recursively contains further data types to print
Return Value
The string representation of the value or
nilif it cannot be processed
View on GitHub
Install in Dash
DataType Class Reference