iphoneobjective-ciosprimitive-typesnsinteger

What is the difference between primitive data type vs an non primitive data type(apple defined data type)?


What's the basic difference between the two..? it would be nice if can someone explain using the example of NSInteger and NSNumber.. Thanks


Solution

  • The main difference is related to where they stay in the memory, objects are stored in the heap while value type are stored directly in the Stack ...

    heap : is an area of memory used for dynamic memory allocation.

    stack : is the section of memory that is allocated for automatic variables within functions. Data is stored in stack using the Last In First Out (LIFO) method.

    About NSInteger and NSNumber :

    NSInteger is nothing more than a synonym for a long integer, while NSNumber is an Objective-C class, a subclass of NSValue to be specific.