Sorry I realise this is a simple question but im new to iOS development and objective-c.
Coming from a c# background, I would try parse the string in the text box then if true assign it to an int to be used in a sum, then assign that to a label.
In iOS and obj-c im having some trouble with the above, and then what I would need to release and alloc.
Any help would be appreciated please.
You can use
NSScannerto do that. For example:As another answer notes, you can use
intValueorintegerValueonNSString. There are a couple of things to note about that approach:Both
NSScannerandintValueallow for whitespace, so45would parse successfully. With NSScanner, you can disable that if you desire by usingsetCharactersToBeSkippedto nil:You can perform normal arithmetic from there on, like
integer + 20, or sum other numbers that you’ve parsed.If locale is important (See Julien’s answer), then you would use the
setLocalemethod on NSScanner with anNSLocalefor example, if we want to ensure the en-US locale is always used:That depends on quite a few things. Are you using ARC? If so then ARC will take care of the release for you. You may want to read up on memory management.