Objective-C also uses variables for storing data in memory like other programming languages. The variables are defined based on the type data type that will be stored. The general rule followed for naming variable are
- Use the camel case convention for variable i.e the first word in lowercase and second word in uppercase. For example if you are planning to store name of station in a variable then you can name it as “stationName”.
- You can also find out datatype of variable and name accordingly. For example, “strName” can tell the variable is of string data type and holds a name.
- Variables must contain only letters and numbers also it is better to avoid using underscore character.
- Be descriptive and avoid single letter or confusing words.
The variables are declared by first defining the datatype, followed by description of variable.
Declaring primitive datatypes
int count = 1;
float width = 23.34;
The object variables are preceded with * before the description of variable.