I am looking to create an iOS calculator, just by using a UITextField. So for example; somebody may type in ‘6 – 3 x 2’ in the UITextField then hit “Done” or “Go” etc. This would then calculate the answer and display it in a UIAlertView.
So firstly I believe that the UITextField text has to be split up into different sections so ‘6’ ‘-‘ ‘3’ ‘*’ ‘2’ would be the separated strings from the UITextField text input. How would I go about separating the text like mentioned above?
How can I then use this information to calculate the answer and to display it?
Use GCMathParser http://apptree.net/parser.htm
It takes an NSString as an input and evaluates it for you.
As Danh said, you can also use DDMathParser https://github.com/davedelong/DDMathParser
An Example(right from the docs)
So you simply send message
evaluateMathto the NSString you want to parse. That’s it)