2

I'm storing a formula 1 && !0 && (0 || 1) in a NSString variable. I need to evaluate this string to a single boolean. Does anyone know of a built in obj-c object for handling this or a 3rd party solution?

Thanks in advance.

Johannes Weiss
  • 52,533
  • 16
  • 102
  • 136
Kyle
  • 434
  • 2
  • 10

2 Answers2

1

I think [NSPredicate parseWithFormat:] and [NSPredicate evaluateWithObject:] could help here.

Johannes Weiss
  • 52,533
  • 16
  • 102
  • 136
  • 1
    I had to reformat my formula string to this "1 == 1 AND NOT 0 == 1 AND ( 0 == 1 OR 1 == 1)" but this works. Thanks – Kyle Feb 06 '13 at 18:52
0

Short of parsing it yourself, you won't be able to evaluate an expression like that in Objective-C during runtime since it is not an interpreted language.

Here are just a few (of many) other resources that pretty much echo this:

This post may get you a step closer to what you are trying to achieve. In any scenario, you will have to parse it yourself.

Community
  • 1
  • 1
Jeremy
  • 8,902
  • 2
  • 36
  • 44