JSExpression

public protocol JSExpression

A JavaScript expression that can be evaluated inside of a web view (WKWebView).

The library provides ready-to-use expression implementations:

You don’t need to implement this protocol yourself.

Expressions are specialized with the ReturnType associated type. Expressions can return any Decodable type. This includes:

  • JSVoid for expressions that do not return a value
  • Primitive values (Strings, Numbers, Booleans, …)
  • Decodable enumerations
  • Objects decodable from JSON
  • Arrays of primitive values
  • Arrays of enumeration cases
  • Arrays of objects
  • Native dictionaries
  • EvaluationResult Extension method

    The result type of the expression.

    Declaration

    Swift

    public typealias EvaluationResult = Result<ReturnType, JSErrorDomain>
  • EvaluationCallback Extension method

    The type of block to execute with the execution result.

    Declaration

    Swift

    public typealias EvaluationCallback = (_ result: EvaluationResult) -> Void

    Parameters

    result

    The result of the evaluation. Will be .success(ReturnType) if a valid return value was parsed ; or .error(JSErrorDomain) if an error was thrown by the web view when evaluating the script.