Simple types of varibles

 

The use of varibles and consts in iPhone programming is very essential for creating

Applications and Games, Varibles helps us store temporary information, calculate data, make run time decitions and much much more.

 

Strings

Strings are combanation of letters (and numbers) - Text;

"This is 1 string"

in Xcode, we use NSString for strings use.

 

NSString *myString = [NSString stringWithString:@"This is 1 string"];

 

This will add a string with letters and numbers to the Varible "myString"

we can also add numbers:

 

NSString *myString = [NSString stringWithFormat:@"%d", 5];

the syntax @"%d", represent an integer (a number)

 

Integers

integers are used to store numbers, there are two easy to use Integer formats that we can use in our app.

int & NSInteger.

Integers are "whole number" format, meaning we can use numbers like 5, 10,1, 0, -5, -20 etc. but we cant

use numbers like -20,-3 etc.

 

In Xcode, we can declare and use integers as shown below

 

int *myInt = 5;

NSInteger *myInt = [myArray integerValue];

 

Floats

 

Float numbers are used to store and work with numbers that are not whole numbers like 5.5, 3,3 etc.

 

In Xcode, we can declare and use Float numbers as shown below

 

float myFloat = 3.41;