Using codec

To get a default codec do this:

let coder: ScaleCoder = ScaleCoder.default()

You might instantiate it using a custom adapter, but all examples will cover common interface of a codec.

It's very easy as that to encode or decode objects like this:

let coder: ScaleCoder
let int: Int32

let encodedValue = try coder.encoder.encode(int)
let decodedValue = try coder.decoder.decode(Int32.self, from: encodedValue)

Same interface applies to every possible type.

Fixed size arrays

Even though Swift is a very powerful and wonderful language, it misses fixed size arrays.

This is one of the features in Substrate, and is used extensively.

To declare fixed size array as one of the variables, please use next syntax:

struct MyFixedSizeArray {
    let string: String
    let fixedSzieArray = Array3(wrappedValue: [1, 2, 3])

Last updated