views:

265

answers:

1

In a SOAP app, all communication with the server is as text, when the server needs an integer it is the text value that gets sent and returned integers are sent back as text.

To have the app working with integers one has to convert the returned strings into numbers e.g. NSInteger but then to, for example, save them to an array they must be objects (NSNumber) but then whenever the numeric value is needed you have to extract it so is it better to leave all number based variables as NSStrings & only extract the numeric value if needed?

Basically my question is, in a soap app, isn't it simpler to just have all variables as NSStrings? Since they are similar to NSNumber objects in terms of usage and leaving all numbers as strings at least saves having to convert back & forth whenever there is server communication involved.

A: 

Storage of an integer in an NSNumber will likely have lower overhead — however minimal it might seem — compared with an NSString. A character string can be multiple bytes per glyph depending on the character encoding, and then you need a null character at the end of the string to terminate it.

A parser has to work through all of that to turn a string back into an integer at the end of the day, such as when you will inevitably need to do arithmetic on these values.

Further, using NSNumber will make it clearer to you what primitive data type you are working with from the SOAP request or response, not only when you write your app, but when you come back to it several months down the line and you need to make changes.

Alex Reynolds
I thought it was something along those lines, so essentially using variables of the data type is a better idea than just using strings for everything, correct?
Spider-Paddy
Yes, that is correct.
Alex Reynolds