⌘K

Utils

Methods

findWindowSizeClass(::_:)

Determines the appropriate value for a property based on the device's size class.

public func findWindowSizeClass(
    _ vertical: UserInterfaceSizeClass?,
    _ horizontal: UserInterfaceSizeClass?,
    _ prop: NativeBlockPropertyModel?
) -> String?

Parameters

  • vertical: The vertical size class of the device (e.g., .compact or .regular).
  • horizontal: The horizontal size class of the device (e.g., .compact or .regular).
  • prop: The NativeBlockPropertyModel containing values for mobile, tablet, and desktop.

Returns

The value corresponding to the device's size class (mobile, tablet, or desktop), or nil if no value is found.


Extensions on String

toCGFloat()

Converts a string representation of a number to a CGFloat.

public func toCGFloat() -> CGFloat?

Returns

A CGFloat if the string can be converted to a number; otherwise, nil.


Extensions on Color

Color(hex:)

Initializes a Color from a hexadecimal string.

public init?(hex: String)

Parameters

  • hex: A hexadecimal string representing the color. Formats: #RRGGBB or #RRGGBBAA.

Returns

A Color if the hexadecimal string is valid; otherwise, nil.

Example Usage
let color = Color(hex: "#FF5733")
print(color) // Output: Optional(Color(red: 1.0, green: 0.34, blue: 0.2, opacity: 1.0))

blockHasSlot(blocks:slot:)

Checks if a block contains a specific slot.

public func blockHasSlot(blocks: [String: NativeBlockModel], slot: String) -> Bool

Parameters

  • blocks: A dictionary of block identifiers to their corresponding NativeBlockModel instances.
  • slot: The slot identifier to check for in the blocks.

Returns

true if the slot is found in any block; otherwise, false.


blockProvideSlot(blockProps:slotType:)

Provides the NativeBlockSlotModel for the specified slot type if the block supports it.

public func blockProvideSlot(blockProps: BlockProps, slotType: String) -> NativeBlockSlotModel?

Parameters

  • blockProps: The properties of the block, including its sub-blocks.
  • slotType: The type of slot to check and provide.

Returns

The NativeBlockSlotModel for the specified slot type if the block supports it; otherwise, nil.


blockProvideEvent(blockProps:eventType:)

Provides an event handler for a specific event type if the block supports it.

public func blockProvideEvent(blockProps: BlockProps, eventType: String) -> (() -> Void)?

Parameters

  • blockProps: The properties of the block, including its event handling logic.
  • eventType: The type of event to check and provide a handler for.

Returns

A closure representing the event handler if the event type is supported; otherwise, nil.


blockHandleEvent(blockProps:eventAction:eventType:)

Handles an event for a block by invoking the appropriate action handler.

public func blockHandleEvent(blockProps: BlockProps, eventAction: NativeActionModel, eventType: String)
A string with substituted variable values or nil if input is nil.
### actionHandleVariableValue(actionProps:variable:)
Handles variable substitution in an action context.
``` swift
public func actionHandleVariableValue(actionProps: ActionProps, variable: NativeVariableModel?) -> String?
Example Usage:
let variable = NativeVariableModel(value: "{var:username}")
let result = actionHandleVariableValue(actionProps: props, variable: variable)
print(result) // Output: "John" (if username variable is "John")

Parameters

  • actionProps: The properties associated with the action being executed.
  • variable: The variable model to be processed.

Supported values

  • {var:variable-key}: Replaces with the value of the variable.
  • {index}: Replaces with the list item index.
  • #SCRIPT #ENDSCRIPT: Replaces JavaScript code snippets within #SCRIPT and #ENDSCRIPT tags with their evaluated results.

Returns

The processed string value of the variable, or nil if the variable is invalid.

Extensions on String

toCGFloat()

Converts a string representation of a number to a CGFloat.

public func toCGFloat() -> CGFloat?

Returns

A CGFloat if the string can be converted to a number; otherwise, nil.