Objective-C: type conversion
Tuesday, June 23, 2009 With some high-level languages such as JavaScript or PHP, where the data is not typed or otherwise can not be, we are "spoiled" to compare or convert integers and strings, and vice versa, all hidden or manipulated by the interpreter (or compiler ). For example, in JavaScript there are functions of "forcing" (as parseInt() for example) needed in special cases. However, in other circumstances treat the whole without worrying about a particular conversion (explicit), such as:
- 5 ; mioNumero var = 5;
- / / ...
- "Il valore di mioNumero è " + mioNumero ) ; alert ( "The value of mioNumero is" + mioNumero);
In Objective-C, however, the type information is important and the type conversion must be explicit. Besides the casting (best typecasting) we can make use of features and functionality specific to the type conversion. For example, here is how to convert a whole string:
Instead, here's how to convert a string to integer:
- miaStringa integerValue ] ; int mioNumero = [miaStringa integerValue];
- / /
- , miaStringa, mioNumero ) ; NSLog (@ "% @ miaStringa = mioNumero =% i", miaStringa, mioNumero);













There are no comments for this post
Leave a comment