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:
JSVariable
to access a variableJSFunction
to call a functionJSScript
to 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:
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
-
The expected return type of the expression.
Declaration
Swift
associatedtype ReturnType : Decodable
-
decodingStrategy
Default 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
-
EvaluationResult
Extension methodThe result type of the expression.
Declaration
Swift
public typealias EvaluationResult = Result<ReturnType, JSErrorDomain>
-
EvaluationCallback
Extension methodThe 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.