Thursday, 19 February 2015

Collection Objects.

OBJECTIVE:
                    To understand collection objects in objective-c & their usages-Introduction.

APPROACH:
                   1.What is a collection object?-Definition.
                   2.A precise walk through collection objects-Explanation.

SOLUTION:
                   Collection object is a foundation framework class used for storing and managing group of objects.

It's primary role is to store the objects in the form of Array,Dictionary,Set.




This includes both immutable and mutable collection objects:

1.Immutable:-The values stored are static(cannot be changed once created)
-->NsSet,
-->NSArray,
-->NsDictionary.

2.Mutable :-The values stored are dynamic(Values can be altered)
-->NSMutableSet,
-->NsMutableArray,
-->NsMutableDictionary.


NsArray:
             NSArray creates static arrays.they hold the objects in a order.

  And the output of the following code is

As you can see,the order of the objects remains unchanged.


NSSet:
         An NSSet is much same like an NSArray,the only difference is that the objects an NSSet holds are not in order.so when we retrieve them they may come back in any random order,based on how easy it is for the system to retrieve them.

So when is it used?it's used mainly when access speed matters and the order is not much of a concern.

And the output is:
Here,the order of the objects are altered or modified.

while NSSet and NSMutable set store collections of distinct objects and NSCounted Set is used to stores collections of non-distinct objects.(NSCountedSet, a subclass of NSMutableSet, is a mutable set to which you can add a particular object more than once) .

NSDictionary:
                     An NSDictionary stores objects in keys and value pairs.The objects are not ordered but they can be retrieved by addressing them with an arbitrary string value.they allow for a faster insertion and deletion processes.

And the output is:


   









No comments:

Post a Comment