Class
JSTypedArray
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.
Relationships
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
Name | Type | Description |
---|---|---|
length | Int |
The number of elements that will be allocated. |
init(unsafelyWrapping:)
public required init(unsafelyWrapping jsObject: JSObject)
init(arrayLiteral:)
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
Name | Type | Description |
---|---|---|
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?
lengthInBytes
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
withUnsafeBytes(_:)
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
Name | Type | Description |
---|---|---|
body | (UnsafeBufferPointer<Element>) throws -> R |
A closure with an |
Returns
The return value, if any, of the body
closure parameter.