ios - DDMathParser: Parsing dynamic formula which contain $ to refer objects value within dictionary -
i struggling little bit use ddmathparser framework expression requirement have. have json of fields & based on expressions fields can set required, hidden or set value of it.
expressions in required tag in sample json not fixed & not getting how achieve dynamic approach expression.
[ { "name": "firstname", "value": "ameer", **"required": true** }, { "name": "lastname", "value": "shaikh", **"required": "$firstname != ‘’"** }, { "name": "designation", "value": "", **"required": "$firstname == ‘ameer’ && $lastname == ‘shaikh’"** }, { "name": "location", "value": "", **"hidden": false** } ]
actually, expression in json contains $ represent 1 of dictionary objects value json. wherein framework internally treats local variable.
these expressions may have different combinations well. there may several expression apart "required" parameters. need run relevant expressions change in value in ui.
edit
let expression = "$firstname == ‘ameer’ && $lastname == ‘shaikh’" let dict = ["firstname": "amir", "lastname": ""] let e = try! expression(string: expression) let result = try! evaluator.default.evaluate(e, substitutions: dict)
though should parse correct value json, have hard coded substitutions string @ least breakthrough. here, substitutions expect string & double & give error "cannot convert value of type [string: string] expected arg type substitutions (dcitionary). there way pass string: string substitutions?
ddmathparser not built string evaluations. it's technically possible make work, it's bit beyond scope of framework.
for situation, think you'd better off using nspredicate
, does allow string comparisons , variable substitutions.
Comments
Post a Comment