views:

48

answers:

2

I am quite the beginner - but I have a lot of experience with respect to Electrical Engineering and formulas - over 30 years worth! Trying to construct an app for the iPhone. Loaded the SDK, bought myself a Mac, got a couple of "Chapter" pages written by John at Alpha Aviation - who recomended I try this site. How do I - well for example I enetered 400/1.732 - it came out like it was a web address with an underline! How can I get mathematical symbols like - sqare root, to the power of, subscript, superscript. I'd like to insert a few "calculator" pages but don't know how to. Appreciate I have only been doing this for the last week or so - so I am still quite rusty compared to what I wrote many years ago. Can anyone help?

cheers

A: 

You can look at here. Quite enough

A blog about Objective C mathematics

vodkhang
In this case, he's not looking to actually perform the math, but to typeset it.
Brad Larson
+2  A: 

The iPhone supports unicode, which has a fairly good set of mathematical symbols. The easiest way to start is to look in "Special Characters..." in the Edit menu of Xcode or pretty much any Mac application. Find a symbol you want and look for the unicode or utf8 equivalent.

For example, "\u221A" is unicode for the square root symbol. That would be "\xE2\x88\x9A" in UTF8. Either form is fine.

Once you have the string for the symbol, you can use it like any other string. So to make it a button title:

NSString *square_root = @"\xE2\x88\x9A";
[someButton setTitle:square_root forState:UIControlStateNormal];

In the Special Characters window is an insert button you can use to insert characters directly into your source files. This is pretty much fine as long as your source files are UTF8. I tend to use the escape codes from habit.

It is also common practice to put strings like these into a strings files and access them through NSBundle with things like NSLocalizedString. Even if you only have one localization, it lets you keep all the strings in one place.

For more complex mathematical layout, you will probably have to use html in a UIWebView. I think all the standard entities are supported.

drawnonward