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:
JSVariableto access a variableJSFunctionto call a functionJSScriptto run a custom script
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:
JSVoidfor 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
-
The expected return type of the expression.
Declaration
Swift
associatedtype ReturnType : Decodable -
decodingStrategyDefault implementationUndocumented
Default Implementation
The decoding strategy to use to evaluate the validity of the result.
Declaration
Swift
var decodingStrategy: JSDecodingStrategy<ReturnType> { get } -
Creates the JavaScript text of the expression.
Declaration
Swift
func makeExpressionString() throws -> String
-
EvaluationResultExtension methodThe result type of the expression.
Declaration
Swift
public typealias EvaluationResult = Result<ReturnType, JSErrorDomain> -
EvaluationCallbackExtension methodThe type of block to execute with the execution result.
Declaration
Swift
public typealias EvaluationCallback = (_ result: EvaluationResult) -> VoidParameters
resultThe 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.
View on GitHub
Install in Dash
JSExpression Protocol Reference