Skip to content

Instantly share code, notes, and snippets.

@luismesas
Created August 22, 2012 21:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luismesas/3429720 to your computer and use it in GitHub Desktop.
Save luismesas/3429720 to your computer and use it in GitHub Desktop.
NSString equation evaluator using NSExpression
NSString *equation = @"floor((19-10)/2)";
NSNumber *result = [NSExpression expressionWithFormat:equation];
NSLog(@"%@", result); // logs "4"
@luismesas
Copy link
Author

I have use this on iPhone to evaluate an equation. It's simpler, you don't need to create a NSPredicate, just the NSExpression.

Here is the docs to the compatible parseable functions: “BNF Definition of Cocoa Predicates”

@masters3d
Copy link

How to do this in swift? ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment