Created
August 22, 2012 21:51
-
-
Save luismesas/3429720 to your computer and use it in GitHub Desktop.
NSString equation evaluator using NSExpression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *equation = @"floor((19-10)/2)"; | |
NSNumber *result = [NSExpression expressionWithFormat:equation]; | |
NSLog(@"%@", result); // logs "4" |
How to do this in swift? ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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”