- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在努力使用 DDMathParser 框架来满足我的表达要求。我有字段的 JSON & 基于表达式,某些字段可以设置为必填、隐藏或设置它的值。
示例 JSON 中 required 标记中的表达式不固定,因此不知道如何实现表达式的动态方法。
[
{
"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 $ to represent one of the dictionary objects value from JSON. Wherein framework internally treats it as a local variable.
这些表达式也可能有不同的组合。除了“必需”参数外,可能还有几个表达式。我需要为 UI 中值的任何变化运行所有相关表达式。
编辑
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)
虽然它应该从 JSON 中解析出一个正确的值,但我已经硬编码了替换字符串以至少取得突破。此处,替换期望 String & Double & 给出错误,如 “无法将类型 [String: String] 的值转换为预期的 arg 类型替换 (Dcitionary)。有什么方法可以传递 String: 字符串替换吗?
最佳答案
DDMathParser 不是为进行字符串评估而构建的。 技术上可以让它发挥作用,但这有点超出了框架的范围。
对于这种情况,我认为您最好使用 NSPredicate
,它确实允许字符串比较和变量替换。
关于ios - DDMathParser:解析包含 $ 的动态公式以引用字典中的对象值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45321224/
我正在使用 DDMathParser在我的应用程序中,最近发现需要在 () 圆括号内获取任何一组数字的出现(非常技术性!)。例如,我需要获取 (6+5) 从 6+7/8(6+5) 。具体来说,我希望能
我在我的 Xcode 项目中使用 DDMathParser。我有内存泄漏,我无法解决它。 Instruments 给了我以下泄露的对象: _DDNumberExpression _DDFunction
如何将自己的常量添加到DDMathParser中?例如,Fe = 55.845。 而且我可以像pi()这样使用它。 谢谢! 最佳答案 根据DDMathParser Wiki,内置常量如pi are f
我想知道如果DDMathParser支持,如何在Xcode中取数字的立方根,甚至更好。甚至更好的是,我如何扎下第x个根。 谢谢, 问候。 最佳答案 是的,DDMathParser支持以下功能: NSN
我尝试根据用户输入(字符串)构建使用 DDMathParser 计算的表达式字符串 例如:3 + ln(2) + var 我尝试使用 DDMathParser 中的内置 Tokenizer 函数来查找
我正在使用 DDMathParser 为 iOS 构建一个计算器应用程序。 我想知道如何将像 5+900/32 这样的表达式 (NSString) 分隔成单独的数值:5 、900 和 32。 我更愿意
我正在注册一个求和函数,它是 sum(expression,initial,final)。 expression 包含独立变量 x 并且 initial 和 final 是整数。例如,sum(2x,2
我正在构建一个应用程序,该应用程序使用 Dave DeLong 的 DDMathParser 绘制文本给定函数。我需要知道(对于我评估的每个“x”)解决方案是否存在,或者它只给我 0.00 因为它无法
我正在使用 DDMathParser 来解析字符串表达式。我正在处理一个表达式“(2+x)6+2x+2y=5y+2x”,我正在尝试解析它并使用 DDMathParser 对其进行评估.它可以被认为是我
我正在努力使用 DDMathParser 框架来满足我的表达要求。我有字段的 JSON & 基于表达式,某些字段可以设置为必填、隐藏或设置它的值。 示例 JSON 中 required 标记中的表达式
在我的 Xcode 项目中,我需要在 ViewController.mm 中重命名我的 ViewController.m,但我还需要 DDMathParser。 我在 .m 文件中编译解析器,没有任何
我正在尝试通过 DDMathParser 内置的机制在 Swift 中定义和格式化自定义函数。我尝试按照 Wiki 上的说明进行操作,但对于 Swift 编码相对较新的人来说,没有足够的细节。我想要创
我正在尝试在我的应用程序中使用 DDMathParser,但很难让它以百分比形式使用 % 符号,而不是模数。 wiki 建议如下 - % 符号通常被解释为模运算符。但是,DDMathParser.h
我已经在 stackoverflow 上找到了我的问题的解决方案,但它是在 Objective-C 中的。请参阅此链接 DDMathParser - Getting tokens 我将其翻译成 Swi
各位,我是 Stack Overflow(和 DDMathParser)的新手,但来到这里是因为当我尝试在 objective-c++ 文件 (main.mm) 中使用 DDMathParser 时出
我有一个NSString: n + (n - 米) 我可以使用 DDMathParser 创建表达式对象吗? 例如,我有基本表达式 n + (n - m),但我需要能够将基本表达式 n + (n -
我添加了 DDMathParser作为我的 Git 存储库中的一个子模块,在运行它之后,代码似乎只适用于 OS X。它立即在 DemoController.h 等中给我以下错误: 找不到“Cocoa/
我正在使用 DDMathParser 来解析公式并计算结果,效果很好。 问题: 如果替换字典中不存在变量,是否可以将变量设置为默认值? 示例: 我的公式 $a + $b 需要两个变量 $a 和 $b
我对 swift 和开发我的第一个 iOS 应用程序完全陌生。我需要用它来使用 DDMathParser。我按照他们网站上的指南操作,但在导入语句时遇到错误 进口申报中的预期标识符 预期的表达 导入语
DDMathParser:如何让解析器知道函数的输入(即 sin 函数)是度数还是弧度?如果“模式”是度数,我想执行:sin(n *2 *pi/360),如果“模式”是弧度,则只执行 sin(n)。
我是一名优秀的程序员,十分优秀!