How to make an iOS calculator just using a UITextField

I want to create an iOS calculator just using a UITextField. For example; someone can type “6 - 3 x 2” into a UITextField, then click “Finish” or “Go”, etc. Then it will calculate the response and display it in the UIAlertView.

So, firstly, I believe that the text of UITextField should be divided into different sections, so '6' '-' '3' '*' '2' will be shared lines from UITextField text input. How would I like to separate the text as above?

How can I use this information to calculate the response and display?

+3
source share
2 answers

GCMathParser http://apptree.net/parser.htm

NSString .

, DDMathParser https://github.com/davedelong/DDMathParser

( )

NSString* mathstring = @"tan(dtor(45))";
double result = [mathstring evaluateMath];    // returns 0.999999999999...

, evaluateMath NSString, . )

+5

NSPredicate :

NSPredicate * parsed = [NSPredicate predicateWithFormat:@"22/7.0 + (13*42) - 1024 = 0"];
NSExpression * left = [(NSComparisonPredicate *)parsed leftExpression];
NSNumber * result = [left expressionValueWithObject:nil context:nil];
NSLog(@"result: %@", result);

, tan .. .

0

All Articles