Wednesday 1 May 2013

Differences Between NSArray And NSSet in Objective C



NSSet
  • Primarily access items by comparison
  • Unordered
  • Does not allow duplicates
NSArray
  • Can access items by index
  • Ordered
  • Allows duplicates
Example


    NSSet *set = [NSSet setWithObjects:@"Amit",@"Rakesh",@"Kiran",@"Jai",@"zebra",@"Amit",@"Kiran"nil];
    NSArray *arr = [[NSArray alloc]initWithObjects:@"Amit",@"Rakesh",@"Kiran",@"Jai",@"zebra",@"Amit",@"Kiran"nil];
    
    NSLog(@"%@",set);
    NSLog(@"%@",arr);


outPut

2013-05-01 11:45:53.881 FirstStoryBoardViewController[630:c07] {(
    Jai,
    zebra,
    Rakesh,
    Amit,
    Kiran
)}
2013-05-01 11:45:54.384 FirstStoryBoardViewController[630:c07] (
    Amit,
    Rakesh,
    Kiran,
    Jai,
    zebra,
    Amit,
    Kiran
)

1 comment:

  1. Then how to fetch the values of NSSet we can fetch value of array at index position but what about NSSet

    ReplyDelete