JsonLogic
public final class JsonLogic
It parses json rule strings and executes the rules on provided data.
-
It parses the string containing a json logic and caches the result for reuse. All calls to
applyRule()
will use the same parsed rule.Throws
JSONLogicError.canNotParseJSONRule
If The jsonRule could not be parsed, possible the syntax is invalidParseError.UnimplementedExpressionFor(_ operator: String)
: If you pass an json logic operation that is not currently implementedParseError.GenericError(String)
: An error occurred during parsing of the rule
Declaration
Swift
public convenience init(_ jsonRule: String) throws
Parameters
jsonRule
A valid json rule string
-
It parses the string containing a json logic and caches the result for reuse. All calls to
applyRule()
will use the same parsed rule.Throws
JSONLogicError.canNotParseJSONRule
If The jsonRule could not be parsed, possible the syntax is invalidParseError.UnimplementedExpressionFor(_ operator: String)
: If you pass an json logic operation that is not currently implementedParseError.GenericError(String)
: An error occurred during parsing of the rule
Declaration
Swift
public init(_ jsonRule: String, customOperators: [String : (JsonForJsonLogic?) -> JsonForJsonLogic]?) throws
Parameters
jsonRule
A valid json rule string
customOperators
custom operations that will be used during evalution
-
It applies the rule, you can optionally pass data to be used for the rule.
Throws
JSONLogicError.canNotConvertResultToType(Any.Type)
: When the result from the calculation can not be converted to the return type //This throws JSONLogicError.canNotConvertResultToType(Double) let r: Double = JsonLogic(“{ ”===“ : [1, 1] }”).applyRule()JSONLogicError.canNotParseJSONData(String)
: IfjsonDataOrNil
is not valid json
Declaration
Swift
public func applyRule<T>(to jsonDataOrNil: String? = nil) throws -> T
Parameters
jsonDataOrNil
Data for the rule to operate on