Variables in Objective-C

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

  1. 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”.
  2. 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.
  3. Variables must contain only letters and numbers also it is better to avoid using underscore character.
  4. 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

Examples :-

int count = 1;

float width = 23.34;

Declaring Objects

NSString *description;

NSArray *months;

The object variables are preceded with * before the description of variable.

In Category: Apple, Develop

Ravi Shankar

A Software developer and blogger who is always looking to provide technical help to the wider community.

Show 0 Comments
No comments yet. Be the first.

Leave a Comment

Get your free copies of the following tech guides by joining the Digital Answers mailing list.