Mutable Versus Immutable If a data type is mutable, you can change if after it is initialized. For instance, you can change one of the values in a mutable array, or add or remove values. In contrast, you must provide the values to an im‐ mutable data type when you initialize it, and cannot add to them, remove them, or change them later. Immutable types are useful be‐ cause they are more efficient, and because they can prevent errors when the values are meant to stay the same throughout the life of the data.
NSInteger and NSUInteger Variables of this type can hold integral values such as 10, 20, etc. The NSInteger type allows negative values as well as positive ones, but the NSUInteger data type is the Unsigned type, hence the U in its name. Remember, the phrase unsigned in programming languages in the context of numbers always means that the number must not be negative. Only a signed data type can hold negative numbers.
CGFloat Holds floating point variables with decimal points, such as 1.31 or 2.40.
NSString Allows you to store strings of characters. We will see examples of this later.
NSNumber Allows you to store numbers as objects.
id Variables of type id can point to any object of any type. These are called untyped objects. Whenever you want to pass an object from one place to another but do not wish to specify its type for whatever reason, you can take advantage of this data type.
NSDictionary and NSMutableDictionary These are immutable and mutable variants of hash tables. A hash table allows you to store a key and to associate a value to that key, such as a key named phone_num that has the value 05552487700. Read the values by referring to the keys associated with them. NSArray and NSMutableArray Immutable and mutable arrays of objects. An array is an ordered collection of items. For instance, you may have 10 string objects that you want to store in memory. An array could be a good place for that. NSSet, NSMutableSet, NSOrderedSet, NSMutableOrderedSet Sets are like arrays in that they can hold series of objects, but they differ from arrays in that they contain only unique objects. Arrays can hold the same object multiple
times, but a set can contain only one instance of an object. I encourage you to learn the difference between arrays and sets and use them properly. NSData and NSMutableData Immutable and mutable containers for any data. These data types are perfect when you want to read the contents of a file, for instance, into memory. Some of the data types that we talked about are primitive, and some are classes. You’ll just have to memorize which is which. For instance, NSInteger is a primitive data type, but NSString is a class, so objects can be instantiated of it. Objective-C, like C and C++, has the concept of pointers. A pointer is a data type that stores the memory address where the real data is stored. You should know by now that pointers to classes are denoted using an asterisk sign: NSString *myString = @"Objective-C is great!"; Thus, when you want to assign a string to a variable of type NSString in Objective-C, you simply have to store the data into a pointer of type NSString *. However, if you are about to store a floating point value into a variable, you wouldn’t specify it as a pointer since the data type for that variable is not a class: /* Set the myFloat variable to PI */ CGFloat myFloat = M_PI; If you wanted to have a pointer to that floating point variable, you could do so as follows: /* Set the myFloat variable to PI */ CGFloat myFloat = M_PI; /* Create a pointer variable that points to the myFloat variable */ CGFloat *pointerFloat = &myFloat; Getting data from the original float is a simple dereference (myFloat), whereas getting the value of through the pointer requires the use of the asterisk (*pointerFloat). The pointer can be useful in some situations, such as when you call a function that sets the value of a floating-point argument and you want to retrieve the new value after the function returns. Going back to classes, we probably have to talk a bit more about classes before things get lost in translation, so let’s do that next.
http://vishal-sata.blogspot.com