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.canNotParseJSONRuleIf 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) throwsParameters
jsonRuleA 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.canNotParseJSONRuleIf 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]?) throwsParameters
jsonRuleA valid json rule string
customOperatorscustom 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): IfjsonDataOrNilis not valid json
Declaration
Swift
public func applyRule<T>(to jsonDataOrNil: String? = nil) throws -> TParameters
jsonDataOrNilData for the rule to operate on
View on GitHub
JsonLogic Class Reference