JavaScriptKit Documentation

Class JSTyped​Array

public class JSTypedArray<Element>: JSBridgedClass, ExpressibleByArrayLiteral where Element: TypedArrayElement  

A wrapper around all JavaScript TypedArray classes that exposes their properties in a type-safe way.

%81 JSTypedArray JSTypedArray ExpressibleByArrayLiteral ExpressibleByArrayLiteral JSTypedArray->ExpressibleByArrayLiteral JSBridgedClass JSBridgedClass JSTypedArray->JSBridgedClass

Conforms To

JSBridgedClass

Conform to this protocol when your Swift class wraps a JavaScript class.

ExpressibleByArrayLiteral

Initializers

init(length:​)

public init(length: Int)  

Initialize a new instance of TypedArray in JavaScript environment with given length. All the elements will be initialized to zero.

Parameters

length Int

The number of elements that will be allocated.

init(unsafely​Wrapping:​)

public required init(unsafelyWrapping jsObject: JSObject)  

init(array​Literal:​)

public required convenience init(arrayLiteral elements: Element...)  

init(_:​)

public convenience init(_ array: [Element])  

Initialize a new instance of TypedArray in JavaScript environment with given elements.

Parameters

array [Element]

The array that will be copied to create a new instance of TypedArray

init(_:​)

public convenience init<S: Sequence>(_ sequence: S) where S.Element == Element  

Convenience initializer for Sequence.

Properties

constructor

public class var constructor: JSFunction?  

js​Object

public var jsObject: JSObject

length​InBytes

public var lengthInBytes: Int  

Length (in bytes) of the typed array. The value is established when a TypedArray is constructed and cannot be changed. If the TypedArray is not specifying a byteOffset or a length, the length of the referenced ArrayBuffer will be returned.

Methods

with​Unsafe​Bytes(_:​)

public func withUnsafeBytes<R>(_ body: (UnsafeBufferPointer<Element>) throws -> R) rethrows -> R  

Calls the given closure with a pointer to a copy of the underlying bytes of the array's storage.

Parameters

body (Unsafe​Buffer​Pointer<Element>) throws -> R

A closure with an UnsafeBufferPointer parameter that points to the contiguous storage for the array. If body has a return value, that value is also used as the return value for the withUnsafeBytes(_:) method. The argument is valid only for the duration of the closure's execution.

Returns

The return value, if any, of the body closure parameter.